From 84f6bae039bc523677e959b1bbdb6f072b6ae49c Mon Sep 17 00:00:00 2001
From: Vermaas <vermaas@astron.nl>
Date: Thu, 1 Aug 2024 14:23:45 +0200
Subject: [PATCH] fix storage_location creation

---
 atdb/taskdatabase/models.py                      |  2 +-
 atdb/taskdatabase/services/activities_handler.py | 10 +++++-----
 atdb/taskdatabase/tests/test_update_activity.py  |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/atdb/taskdatabase/models.py b/atdb/taskdatabase/models.py
index 24254a15..a289b34c 100644
--- a/atdb/taskdatabase/models.py
+++ b/atdb/taskdatabase/models.py
@@ -110,7 +110,7 @@ class Activity(models.Model):
     def __str__(self):
         return str(self.sas_id)
 
-    def create_storage_location(self, task):
+    def create_storage_location(self):
         workdir = Configuration.objects.get(key='executor:workdir').value
         self.storage_location = workdir.replace('run', 'aggregate') + str(self.sas_id)
 
diff --git a/atdb/taskdatabase/services/activities_handler.py b/atdb/taskdatabase/services/activities_handler.py
index eadd462f..45cfd5d6 100644
--- a/atdb/taskdatabase/services/activities_handler.py
+++ b/atdb/taskdatabase/services/activities_handler.py
@@ -202,6 +202,11 @@ def update_processed_and_aggregate(task):
 
     if (task.workflow.aggregation_strategy == AggregationStrategy.COLLECT_H5.value):
 
+        # check if there is already a storage_location, if not, add it.
+        if not activity.storage_location:
+            # for this aggregation_strategy, the activity storage_location is the workdir of the aggregation task
+            activity.create_storage_location()
+
         # check if the activity is ready to collect H5 data
         if (not activity.is_aggregated and
                 activity.status != State.COLLECTING_DATA.value and
@@ -215,11 +220,6 @@ def update_processed_and_aggregate(task):
             else:
                 aggregation_task = aggregation_tasks[0]
 
-            # check if there is already a storage_location, if not, add it.
-            if not activity.storage_location:
-                # for this aggregation_strategy, the activity storage_location is the workdir of the aggregation task
-                activity.create_storage_location()
-
             # this means that its tasks know that they should copy their H5 files to the storage_location
             # (but the tasks cannot do that, the aggregator service does)
             activity.status = State.COLLECTING_DATA.value
diff --git a/atdb/taskdatabase/tests/test_update_activity.py b/atdb/taskdatabase/tests/test_update_activity.py
index 4a138700..364f1036 100644
--- a/atdb/taskdatabase/tests/test_update_activity.py
+++ b/atdb/taskdatabase/tests/test_update_activity.py
@@ -216,4 +216,4 @@ class TestUpdateActivity(TestCase):
 
         expected = "/project/ldv/Share/aggregate/113"
         actual = self.task11.activity.storage_location
-        #self.assertEqual(actual, expected)
+        self.assertEqual(actual, expected)
-- 
GitLab