Skip to content
Snippets Groups Projects
Commit c60cbfb4 authored by Nico Vermaas's avatar Nico Vermaas
Browse files

getting rid of taskID (database change)

skeleton for 'get_size' endpoint
parent 553b27f5
Branches
No related tags found
No related merge requests found
Pipeline #8599 passed
# 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',
),
]
......@@ -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)
......
......@@ -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',
......
......@@ -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
......
......@@ -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>',
......
......@@ -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,
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment