From 1812ce52de89cc4d2dbd519db8dee1d09da5edf0 Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Thu, 14 Oct 2021 16:52:02 +0200
Subject: [PATCH] TMSS-1093: when called from the commandline, don't use
 parallel uploading to make the log lines sequential/readable

---
 SAS/TMSS/client/lib/populate.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/SAS/TMSS/client/lib/populate.py b/SAS/TMSS/client/lib/populate.py
index e63fee7091a..387a47b8a20 100644
--- a/SAS/TMSS/client/lib/populate.py
+++ b/SAS/TMSS/client/lib/populate.py
@@ -23,7 +23,8 @@ def populate_main():
 
     (options, args) = parser.parse_args()
 
-    populate_schemas(options.schema_dir, options.rest_credentials)
+    # when called from the commandline, don't use parallel uploading to make the log lines sequential/readable
+    populate_schemas(options.schema_dir, options.rest_credentials, parallel=False)
 
     # now that the schema's were uploaded, let's populate the dependend task connectors, and the permissions
     from lofar.sas.tmss.tmss import setup_and_check_tmss_django_database_connection_and_exit_on_error
@@ -33,7 +34,7 @@ def populate_main():
     populate_connectors()
 
 
-def populate_schemas(schema_dir: str=None, dbcreds_name: str=None):
+def populate_schemas(schema_dir: str=None, dbcreds_name: str=None, parallel: bool=True):
     with TMSSsession.create_from_dbcreds_for_ldap(dbcreds_name=dbcreds_name) as client:
         if schema_dir is None:
             schema_dir = os.path.expandvars('$LOFARROOT/share/tmss/schemas')
@@ -186,14 +187,14 @@ def populate_schemas(schema_dir: str=None, dbcreds_name: str=None):
 
         # then, upload the remaining templates in parallel
         rest_templates = [template for template in schema_templates_dict.values()]
-        with ThreadPoolExecutor() as executor:
+        with ThreadPoolExecutor(max_workers=None if parallel else 1) as executor:
             executor.map(upload_template, rest_templates)
 
         # and finally, the strategy_templates
         for strategy_templates in (reservation_strategy_templates,
                                    observing_strategy_templates,
                                    scheduling_set_strategy_templates):
-            with ThreadPoolExecutor() as executor:
+            with ThreadPoolExecutor(max_workers=None if parallel else 1) as executor:
                 executor.map(upload_strategy_templates, strategy_templates)
 
 if __name__=='__main__':
-- 
GitLab