From fdaafb21e648704313dc8b9d709986d40b6426c7 Mon Sep 17 00:00:00 2001
From: Cyril Danilevski <cyril.danilevski@xfel.eu>
Date: Mon, 5 Sep 2022 10:48:51 +0200
Subject: [PATCH] Check for beamtimes only when proposal in Running or Active

---
 webservice/webservice.py | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/webservice/webservice.py b/webservice/webservice.py
index d8a5e5326..394db06c3 100644
--- a/webservice/webservice.py
+++ b/webservice/webservice.py
@@ -568,24 +568,24 @@ async def get_slurm_partition(
         logging.error(Errors.MDC_RESPONSE.format(response))
 
     partition = 'exfel'
+    active_now = False
 
     status_beamtime = response.json().get('flg_beamtime_status', 'whoopsie')
 
     if status_beamtime in ['R', 'A']:
         partition = 'upex-high' if action == 'dark' else 'upex-middle'
 
-    # A proposal can have several beamtimes during which data can be taken
-    # that are independent from the start and end dates.
-    beamtimes = response.json().get('beamtimes', [])
-    active_now = False
-    now = datetime.now().timestamp()
-    for beamtime in beamtimes:
-        begin = datetime.fromisoformat(beamtime['begin_at']).timestamp()
-        end = datetime.fromisoformat(beamtime['end_at']).timestamp()
-        if begin <= now <= end:
-            active_now = True
-            break
-    partition = partition if active_now else 'exfel'
+        # A proposal can have several beamtimes during which data can be taken
+        # that are independent from the start and end dates.
+        beamtimes = response.json().get('beamtimes', [])
+        now = datetime.now().timestamp()
+        for beamtime in beamtimes:
+            begin = datetime.fromisoformat(beamtime['begin_at']).timestamp()
+            end = datetime.fromisoformat(beamtime['end_at']).timestamp()
+            if begin <= now <= end:
+                active_now = True
+                break
+        partition = partition if active_now else 'exfel'
 
     # NOTE: non-zero at cycle index 4 (`str(cycle)[4]`) indicates commissioning
     if run_id and cycle and str(cycle)[4] != '0':
-- 
GitLab