1717parse_app_properties (globals (), config .paths .task_generator .task_generator )
1818
1919
20- def generate_tasks (task_window_duration :str , task_window_reference :str , process_conf :str , timeframe_conf :str , timetravel_now :str = None ):
20+ def generate_tasks (task_window_duration : str ,
21+ task_window_reference : str ,
22+ process_conf : dict ,
23+ timeframe_conf : dict ,
24+ timetravel_now : str | None = None ,
25+ process_time_shift : str | None = None ,
26+ ):
2127 """
2228 Generates a sequence of tasks based on the given process configuration and time frame definitions.
2329
@@ -26,9 +32,9 @@ def generate_tasks(task_window_duration:str, task_window_reference:str, process_
2632 within which the tasks are generated.
2733 task_window_reference (str): a string identifying the reference point in time for the task window,
2834 as defined in the `reference_times` dict imported from `time_helper.py`.
29- process_conf (str): path to a JSON file specifying the process configuration, as described in the
35+ process_conf (dict): JSON file specifying the process configuration, as described in the
3036 documentation.
31- timeframe_conf (str): path to a JSON file specifying the time frame definitions, as described in the
37+ timeframe_conf (dict): JSON file specifying the time frame definitions, as described in the
3238 documentation.
3339
3440 Yields:
@@ -41,16 +47,12 @@ def generate_tasks(task_window_duration:str, task_window_reference:str, process_
4147
4248 # TODO - add validation against schema
4349
44- # Load the time frame configuration from the specified file.
45- time_frames = json .loads (Path (timeframe_conf ).read_text ())
46-
4750 # Convert the list of time frames to a dictionary for easier access.
48- time_frames = {time_frame ["@id" ].split ("/" )[- 1 ]: time_frame for time_frame in time_frames }
51+ time_frames = {time_frame ["@id" ].split ("/" )[- 1 ]: time_frame for time_frame in timeframe_conf }
4952
5053 # Load the process configuration from the specified file.
51- processes = json .loads (Path (process_conf ).read_text ())
5254
53- for process in processes :
55+ for process in process_conf :
5456
5557 # Loop through each run in the process configuration.
5658 for run in process ["runs" ]:
@@ -82,21 +84,24 @@ def generate_tasks(task_window_duration:str, task_window_reference:str, process_
8284 else :
8385 _ = runs .get_next (datetime )
8486
85-
86-
8787 logger .info (f"Next run of { run ['@id' ]} at { run_timestamp } " )
8888
8989 if not (run_timestamp >= run_window_start and run_timestamp <= run_window_end ):
90- logger .info (f"Run at { run_timestamp } not in window [{ run_window_start } /{ run_window_end } ] -> { run ['@id' ]} " )
90+ logger .info (f"Run at { run_timestamp } not in window [{ run_window_start } /{ run_window_end } ] -> { run ['@id' ]} " )
9191
9292 # Loop through each timestamp in the current run.
9393 while run_timestamp <= run_window_end :
94- logger .info (f"Run at { run_timestamp } in window [{ run_window_start } /{ run_window_end } ] -> { run ['@id' ]} " )
94+ logger .info (f"Run at { run_timestamp } in window [{ run_window_start } /{ run_window_end } ] -> { run ['@id' ]} " )
9595
9696 # Get the reference time for the current timestamp in the time frame.
9797 reference_time_start = reference_times [time_frame ["reference_time_start" ]](run_timestamp )
9898 reference_time_end = reference_times [time_frame ["reference_time_end" ]](run_timestamp )
9999
100+ # Change reference time according to time shift config
101+ if process_time_shift :
102+ reference_time_start = reference_time_start + parse_duration (process_time_shift )
103+ reference_time_end = reference_time_end + parse_duration (process_time_shift )
104+
100105 # Calculate the start and end of the period for the current task.
101106 job_period_start = reference_time_start + parse_duration (time_frame ["period_start" ])
102107 job_period_end = reference_time_end + parse_duration (time_frame ["period_end" ])
@@ -128,8 +133,7 @@ def generate_tasks(task_window_duration:str, task_window_reference:str, process_
128133 task_id = str (uuid4 ())
129134 task_timestamp = utcnow ().isoformat ()
130135
131- logger .info (f"Task { timestamp_utc } in window [{ job_period_start_utc } /{ job_period_end_utc } ] -> Job: { job_id } " )
132-
136+ logger .info (f"Task { timestamp_utc } in window [{ job_period_start_utc } /{ job_period_end_utc } ] -> Job: { job_id } " )
133137
134138 task = {
135139 "@context" : "https://example.com/task_context.jsonld" ,
@@ -157,7 +161,7 @@ def generate_tasks(task_window_duration:str, task_window_reference:str, process_
157161 "timestamp_utc" : f"{ timestamp_utc :%Y-%m-%dT%H:%M} " ,
158162 "reference_schedule_start_utc" : f"{ schedule_start_utc :%Y-%m-%dT%H:%M} " ,
159163 "reference_schedule_end_utc" : f"{ schedule_end_utc :%Y-%m-%dT%H:%M} " ,
160- "reference_schedule_timehorizon " : TASK_SCHEDULE_TIMEHORIZON
164+ "reference_schedule_time_horizon " : TASK_SCHEDULE_TIME_HORIZON
161165 }
162166 }
163167
@@ -185,6 +189,7 @@ def generate_tasks(task_window_duration:str, task_window_reference:str, process_
185189
186190 # Next Task
187191 timestamp_utc = timestamps_utc .get_next (datetime )
192+
188193 # Next Run
189194 run_timestamp = runs .get_next (datetime )
190195
@@ -255,7 +260,7 @@ def update_task_status(task, status_text, publish=True):
255260 try :
256261 publish_tasks ([task ])
257262 except :
258- logger .warning ("Task Publication to ELK failed" )
263+ logger .warning ("Task publication to Elastic failed" )
259264
260265
261266def set_task_version (task , elk_index = 'emfos-tasks*' ):
@@ -272,11 +277,8 @@ def set_task_version(task, elk_index='emfos-tasks*'):
272277 else :
273278 if task ['task_properties' ]['version' ] == 'AUTO' :
274279 task ['task_properties' ]['version' ] = '001'
275-
276280 except :
277- logger .warning ("ELK query for Task versioning unsuccessful, version not updated" )
278-
279-
281+ logger .warning ("Elastic query for task versioning unsuccessful, version not updated" )
280282
281283
282284if __name__ == "__main__" :
0 commit comments