From c60cbfb4bce859a8f3af2f8a30a6abd28bd7381c Mon Sep 17 00:00:00 2001
From: Nico Vermaas <vermaas@astron.nl>
Date: Fri, 29 Jan 2021 08:32:04 +0100
Subject: [PATCH] getting rid of taskID (database change) skeleton for
 'get_size' endpoint

---
 .../migrations/0003_remove_task_taskid.py     | 17 +++++++++++
 atdb/taskdatabase/models.py                   |  1 -
 atdb/taskdatabase/serializers.py              |  2 +-
 atdb/taskdatabase/services/algorithms.py      | 29 ++++---------------
 atdb/taskdatabase/urls.py                     |  8 ++---
 atdb/taskdatabase/views.py                    | 24 ++++-----------
 6 files changed, 33 insertions(+), 48 deletions(-)
 create mode 100644 atdb/taskdatabase/migrations/0003_remove_task_taskid.py

diff --git a/atdb/taskdatabase/migrations/0003_remove_task_taskid.py b/atdb/taskdatabase/migrations/0003_remove_task_taskid.py
new file mode 100644
index 00000000..9de008f2
--- /dev/null
+++ b/atdb/taskdatabase/migrations/0003_remove_task_taskid.py
@@ -0,0 +1,17 @@
+# Generated by Django 3.1.4 on 2021-01-29 07:31
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('taskdatabase', '0002_auto_20210129_0739'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='task',
+            name='taskID',
+        ),
+    ]
diff --git a/atdb/taskdatabase/models.py b/atdb/taskdatabase/models.py
index 6ecf5323..4251f655 100644
--- a/atdb/taskdatabase/models.py
+++ b/atdb/taskdatabase/models.py
@@ -19,7 +19,6 @@ class Workflow(models.Model):
 class Task(models.Model):
 
     # Task control properties
-    taskID = models.CharField(db_index=True, max_length=30, blank=True, null=True)
     task_type = models.CharField(max_length=20, default="task")
     filter = models.CharField(max_length=30, blank=True, null=True)
     new_status = models.CharField(max_length=50, default="defining", null=True)
diff --git a/atdb/taskdatabase/serializers.py b/atdb/taskdatabase/serializers.py
index d09d1109..a1fc74d1 100644
--- a/atdb/taskdatabase/serializers.py
+++ b/atdb/taskdatabase/serializers.py
@@ -43,7 +43,7 @@ class TaskSerializer(serializers.ModelSerializer):
 
     class Meta:
         model = Task
-        fields = ('id','task_type','taskID','filter','predecessor','successors',
+        fields = ('id','task_type','filter','predecessor','successors',
                   'project','sas_id','priority','purge_policy','resume',
                   'new_workflow_id','new_workflow_uri','workflow',
                   'stage_request_id',
diff --git a/atdb/taskdatabase/services/algorithms.py b/atdb/taskdatabase/services/algorithms.py
index ba254400..c4a434df 100644
--- a/atdb/taskdatabase/services/algorithms.py
+++ b/atdb/taskdatabase/services/algorithms.py
@@ -17,32 +17,15 @@ DJANGO_TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
 logger = logging.getLogger(__name__)
 
 @timeit
-def get_next_taskid(timestamp, taskid_postfix):
+def get_size(status_list):
     """
-    generate a new taskid based on timestamp, with an optional postfix
-    :param timestamp: timestamp on which the taskid is based
-    :param taskid_postfix: optional addition to the tasked, like 190405001_IMG
-    :return: taskid
+    aggregate the sizes of all task with a status in the list
+    :param status_list: list of statuses to consider for the aggregation
+    :return: summed sizes
     """
 
-    logger.info("get_next_taskid("+timestamp+")")
-
-    count = 0
-    while True:
-        count += 1
-        taskid = timestamp + str(count).zfill(3)  # 20180606001
-        taskid = taskid[2:]  # 180606001
-
-        # add an optional postfix, can be used to make pretty pipeline taskis' like 180905001_CAL
-        if taskid_postfix != None:
-            taskid = taskid + taskid_postfix  # 180606001_RAW
-
-        # check if this taskid already exists. If it does, increase the counter and try again
-        logger.info('checking taskid ' + str(taskid) + '..')
-        found = Task.objects.filter(taskID=taskid).count()
-
-        if found==0:
-            return taskid
+    logger.info("get_size("+status_list+")")
+    #todo: implement
 
     return -1
 
diff --git a/atdb/taskdatabase/urls.py b/atdb/taskdatabase/urls.py
index 56ebc80a..95c44d27 100644
--- a/atdb/taskdatabase/urls.py
+++ b/atdb/taskdatabase/urls.py
@@ -18,10 +18,10 @@ urlpatterns = [
     path('logentries/<int:pk>/', views.LogEntryDetailsViewAPI.as_view(), name='logentry-detail-view-api'),
 
     # --- custom requests ---
-    # ex: /atdb/get_next_taskid?timestamp=2019-04-05
-    path('get_next_taskid',
-         views.GetNextTaskIDView.as_view(),
-         name='get-next-taskid-view'),
+    # /atdb/get_size?status__in=defined,staged
+    path('get_size',
+         views.GetSizeView.as_view(),
+         name='get-size-view'),
 
     # --- controller resources ---
     path('tasks/<int:pk>/setstatus/<new_status>/<page>',
diff --git a/atdb/taskdatabase/views.py b/atdb/taskdatabase/views.py
index b7b4b275..1d17b797 100644
--- a/atdb/taskdatabase/views.py
+++ b/atdb/taskdatabase/views.py
@@ -33,7 +33,6 @@ class TaskFilter(filters.FilterSet):
             'project': ['exact', 'icontains'],
             'sas_id': ['exact', 'icontains'],
             'status': ['exact', 'icontains', 'in', 'startswith'],
-            'taskID': ['gt', 'lt', 'gte', 'lte','exact', 'icontains', 'startswith','in'],
             'purge_policy': ['exact'],
             'priority': ['exact'],
         }
@@ -117,7 +116,6 @@ def get_unfiltered_tasks(status):
 
 def get_searched_tasks(search):
     tasks = Task.objects.filter(
-        Q(taskID__contains=search) |
         Q(sas_id__contains=search) |
         Q(task_type__icontains=search) |
         Q(status__icontains=search) |
@@ -224,32 +222,20 @@ def TaskSetStatus(request,pk,new_status,page):
     return redirect('/atdb/?page='+page)
 
 
-# get the next taskid based on starttime and what is currently in the database
-#/atdb/get_next_taskid?timestamp=2019-04-05
-class GetNextTaskIDView(generics.ListAPIView):
+#/atdb/get_size?status__in=defined,staged
+class GetSizeView(generics.ListAPIView):
     queryset = Task.objects.all()
 
     # override list and generate a custom response
     def list(self, request, *args, **kwargs):
 
-        # read the arguments from the request
-        try:
-            timestamp = self.request.query_params['timestamp']
-        except:
-            timestamp = None
-
-        # read the arguments from the request
-        try:
-            taskid_postfix = self.request.query_params['taskid_postfix']
-        except:
-            taskid_postfix = None
-
         # call the business logic
-        taskID = algorithms.get_next_taskid(timestamp, taskid_postfix)
+        status_list = ['defined','staged']
+        size = algorithms.get_size(status_list)
 
         # return a response
         return Response({
-            'taskID': taskID,
+            'size': size,
         })
 
 
-- 
GitLab