diff --git a/atdb/taskdatabase/models.py b/atdb/taskdatabase/models.py index 5f6e51cc8b849143fe3e65ab5b98c4b3e65160b4..49e9aaae7147c01c3931ebe2d73d8e617c0e5f05 100644 --- a/atdb/taskdatabase/models.py +++ b/atdb/taskdatabase/models.py @@ -154,6 +154,7 @@ def check_if_summary(task): for tar in tars: if 'summary' in tar['basename']: # a summary tarball was found, this task is a summary task + logger.info(f'task {task.id} with workflow {task.workflow} is a summary task') return True except: # no 'tar_archive' was found diff --git a/atdb/taskdatabase/urls.py b/atdb/taskdatabase/urls.py index 906ffe5edfa99879158841e8b5d803431e96a006..0c5fb770ee62d9d22860252c8f03d7d5a8c6a105 100644 --- a/atdb/taskdatabase/urls.py +++ b/atdb/taskdatabase/urls.py @@ -133,4 +133,5 @@ urlpatterns = [ #some migration and repair endpoints path('tasks/repair/associate-activities/', views.AssociateActivities, name='associate-activities'), path('tasks/repair/update-activity/<sas_id>', views.UpdateActivitySasId, name='update-activity-sasid'), + path('tasks/repair/update-summary-flag/<task_id>', views.UpdateSummaryFlag, name='update-summary-flag'), ] diff --git a/atdb/taskdatabase/views.py b/atdb/taskdatabase/views.py index 0ff77a34177461537ab5f09977cd1e8685835af8..9ee039c8e20456c02027ba16a71ca5d3f3c0cea9 100644 --- a/atdb/taskdatabase/views.py +++ b/atdb/taskdatabase/views.py @@ -24,6 +24,8 @@ from rest_framework.request import Request from django.conf import settings from .models import Activity, Task, Workflow, LogEntry, Configuration, Job, PostProcessingRule, Monitor, LatestMonitor +from .models import check_if_summary + from .services.common import State from .services.signals import disconnect_signals, connect_signals from .tables import TaskTable @@ -1685,7 +1687,7 @@ class GetUniqueValuesForKey(generics.ListAPIView): @staff_member_required def AssociateActivities(request): - # disconnect the signals to avoid save recursion + # disconnect the signals to avoid unneccesary updates disconnect_signals() #tasks = Task.objects.filter(activity__isnull=True)[:10000] @@ -1734,3 +1736,26 @@ def UpdateActivitySasId(request, sas_id): 'total': total }) +def UpdateSummaryFlag(request, task_id): + # this function is called externally to avoid worker timeouts + # http://localhost:8000/atdb/tasks/repair/update-summary-flag/12345 + + try: + task = Task.objects.get(id=task_id) + if not task.is_summary: + is_summary = check_if_summary(task) + if is_summary: + # disconnect the signals to avoid unneccesary updates + disconnect_signals() + task.save() + connect_signals() + + except Exception as error: + logger.error(error) + return JsonResponse({ + 'error': str(error) + }) + + return JsonResponse({ + 'is_summary': task.is_summary + })