diff --git a/atdb/taskdatabase/models.py b/atdb/taskdatabase/models.py index 05ac8d4beb93245e9c15683a3d1d77e1afb886dd..72101397de590768fcd1df373914f1a5f10a07af 100644 --- a/atdb/taskdatabase/models.py +++ b/atdb/taskdatabase/models.py @@ -21,7 +21,7 @@ class Workflow(models.Model): class Task(models.Model): # Task control properties - task_type = models.CharField(max_length=20, default="task") + task_type = models.CharField(max_length=20, default="regular") filter = models.CharField(max_length=30, blank=True, null=True) new_status = models.CharField(max_length=50, default="defining", null=True) status = models.CharField(db_index=True, default="unknown", max_length=50,blank=True, null=True) diff --git a/atdb/taskdatabase/services/algorithms.py b/atdb/taskdatabase/services/algorithms.py index 7baaa014d0599d4efdc2ca453207b966cfeaada7..511f021e09bb29818a71e9c741769824c4c91830 100644 --- a/atdb/taskdatabase/services/algorithms.py +++ b/atdb/taskdatabase/services/algorithms.py @@ -33,7 +33,7 @@ def get_size(status_list, type): field = 'size_to_process' query = field + '__sum' - tasks = Task.objects.filter(status__in=status_list) + tasks = Task.objects.filter(status__in=status_list).filter(task_type='regular') sum_value = tasks.aggregate(Sum(field))[query] if sum_value == None: @@ -175,7 +175,7 @@ def aggregate_resources_tasks(selection): # get all active tasks if 'active' in selection: - active_tasks = Task.objects.filter(status__in=settings.ACTIVE_STATUSSES) + active_tasks = Task.objects.filter(status__in=settings.ACTIVE_STATUSSES).filter(task_type='regular') # retrieve all unique workflows from the active tasks active_workflows = active_tasks.values('workflow').distinct() @@ -198,7 +198,7 @@ def aggregate_resources_tasks(selection): # get the numbers for this workflow # all tasks for this workflow for the 'grand total' - tasks_per_workflow = Task.objects.filter(workflow=workflow) + tasks_per_workflow = Task.objects.filter(workflow=workflow).filter(task_type='regular') nr_of_tasks_per_workflow = tasks_per_workflow.count() sum_size_to_process = tasks_per_workflow.aggregate(Sum('size_to_process')) @@ -244,7 +244,7 @@ def aggregate_resources_logs(selection): # get all active tasks if 'active' in selection: - active_tasks = Task.objects.filter(status__in=settings.ACTIVE_STATUSSES) + active_tasks = Task.objects.filter(status__in=settings.ACTIVE_STATUSSES).filter(task_type='regular') # retrieve all unique workflows from the active tasks active_workflows = active_tasks.values('workflow').distinct() @@ -294,7 +294,7 @@ def aggregate_resources_logs_version1(): records = [] # get all active tasks - active_tasks = Task.objects.filter(status__in=settings.ACTIVE_STATUSSES) + active_tasks = Task.objects.filter(status__in=settings.ACTIVE_STATUSSES).filter(task_type='regular') active_tasks_count = active_tasks.count() # retrieve all unique workflows @@ -333,7 +333,7 @@ def aggregate_resources_logs_version1(): def construct_link_to_tasks_api(request, status, workflow_id, count): link = str(count) try: - if status in settings.ACTIVE_STATUSSES: + if status in settings.ALL_STATUSSES: query = "?status=" + status + "&workflow__id=" + str(workflow_id) else: if 'failed' in status: diff --git a/atdb/taskdatabase/templates/taskdatabase/index.html b/atdb/taskdatabase/templates/taskdatabase/index.html index aca28baaf862e006415126026c5fb5aaa9360f7a..b2908432dacaa343ab24c336815b7feb37e83812 100644 --- a/atdb/taskdatabase/templates/taskdatabase/index.html +++ b/atdb/taskdatabase/templates/taskdatabase/index.html @@ -80,7 +80,7 @@ {% include 'taskdatabase/pagination.html' %} </div> </div> - <p class="footer"> Version 1.0.0 (17 jan 2021 - 15:00) + <p class="footer"> Version 1.0.0 (18 jan 2021 - 13:00) </div> diff --git a/atdb/taskdatabase/urls.py b/atdb/taskdatabase/urls.py index 236a3a1e50c2d9ded38aae7d99cbcd8711509578..553d5c967f0ebbebc843d1a0ad8ea8acc5ef400d 100644 --- a/atdb/taskdatabase/urls.py +++ b/atdb/taskdatabase/urls.py @@ -33,6 +33,8 @@ urlpatterns = [ path('tasks/<int:pk>/', views.TaskDetailsViewAPI.as_view(), name='task-detail-view-api'), path('tasks-fast/', views.TaskListViewAPIFast.as_view(), name='tasks-api-fast'), path('tasks-fast/<int:pk>/', views.TaskDetailsViewAPIFast.as_view(), name='task-detail-view-api-fast'), + path('postprocessing-tasks/', views.PostProcessingTaskListViewAPI.as_view(), name='postprocessing-tasks-api'), + path('all-tasks/', views.AllTaskListViewAPI.as_view(), name='all-tasks-api'), path('workflows/', views.WorkflowListViewAPI.as_view(), name='workflows-api'), path('workflows/<int:pk>/', views.WorkflowDetailsViewAPI.as_view(), name='workflow-detail-view-api'), diff --git a/atdb/taskdatabase/views.py b/atdb/taskdatabase/views.py index 42c60a8347954267475e417555f80c385ba8a19e..82f5b18b45c3cfefdbe77a7cae9eb57b8cb43822 100644 --- a/atdb/taskdatabase/views.py +++ b/atdb/taskdatabase/views.py @@ -46,6 +46,7 @@ class TaskFilter(filters.FilterSet): model = Task fields = { + 'task_type': ['exact', 'icontains', 'in'], 'creationTime': ['icontains'], 'filter': ['exact', 'icontains'], 'workflow__id' : ['exact', 'icontains'], @@ -68,6 +69,7 @@ class TaskFilterQueryPage(filters.FilterSet): fields = { 'id': ['exact', 'gte', 'lte'], + #'task_type': ['exact','in'], 'workflow__id': ['exact'], 'filter': ['exact', 'icontains'], 'priority': ['exact', 'gte', 'lte'], @@ -204,6 +206,9 @@ class IndexView(ListView): if (search_box is not None): tasks = get_searched_tasks(search_box, sort) + # only return the 'regular' tasks, and not the 'postprocessing' tasks in the GUI + tasks = tasks.filter(task_type='regular') + paginator = Paginator(tasks, config.TASKS_PER_PAGE) # Show 50 tasks per page page = self.request.GET.get('page') @@ -226,9 +231,6 @@ class IndexView(ListView): return tasks -def get_searched_tasks_only_status(search, sort): - tasks = Task.objects.filter(status__in=search).order_by(sort) - return tasks def get_searched_tasks(search, sort): tasks = Task.objects.filter( @@ -329,7 +331,46 @@ class DiagramView(ListView): # ---------- REST API views ----------- # example: /atdb/tasks/ +# this shows only 'regular' tasks and not 'postprocessing' tasks +# the endpoint it kept 'tasks' for backward compatibility reasons. class TaskListViewAPI(generics.ListCreateAPIView): + """ + A pagination list of tasks, unsorted. + """ + model = Task + queryset = Task.objects.filter(task_type='regular').order_by('-priority','id') + #serializer_class = TaskSerializer + + # using the Django Filter Backend - https://django-filter.readthedocs.io/en/latest/index.html + filter_backends = (filters.DjangoFilterBackend,) + filter_class = TaskFilter + + def get_serializer_class(self): + if self.request.method in ['GET']: + return TaskReadSerializer + else: + return TaskWriteSerializer + +class PostProcessingTaskListViewAPI(generics.ListCreateAPIView): + """ + A pagination list of tasks, unsorted. + """ + model = Task + queryset = Task.objects.filter(task_type='postprocessing').order_by('-priority','id') + #serializer_class = TaskSerializer + + # using the Django Filter Backend - https://django-filter.readthedocs.io/en/latest/index.html + filter_backends = (filters.DjangoFilterBackend,) + filter_class = TaskFilter + + def get_serializer_class(self): + if self.request.method in ['GET']: + return TaskReadSerializer + else: + return TaskWriteSerializer + +# all tasks +class AllTaskListViewAPI(generics.ListCreateAPIView): """ A pagination list of tasks, unsorted. """