3030 Sleep ,
3131)
3232from .behaviours import TriggerWorkflow as TriggerWorkflow
33- from .behaviours import UpdateWorkflowStatus
34- from .decorators import FlagGuard
33+ from .behaviours import UpdateWorkflowStatusUntilCompletion
34+ from .decorators import ConditionGuard , FlagGuard , StatusFlagGuard
3535from .state import Package , PackageMeta , ReleaseMeta , Workflow
3636
3737
@@ -110,7 +110,7 @@ def tick(self) -> Iterator[Behaviour]:
110110 yield self
111111
112112
113- class FindWorkflowByUUID (FlagGuard ):
113+ class FindWorkflowByUUID (StatusFlagGuard ):
114114 max_retries : int = 3
115115 poll_interval : int = 5
116116
@@ -145,12 +145,12 @@ def __init__(
145145 None if name == "" else name ,
146146 identify_loop ,
147147 workflow .ephemeral ,
148- "identify_failed " ,
148+ "identify_workflow " ,
149149 log_prefix = log_prefix ,
150150 )
151151
152152
153- class WaitForWorkflowCompletion (FlagGuard ):
153+ class WaitForWorkflowCompletion (StatusFlagGuard ):
154154 poll_interval : int
155155 timeout_seconds : int
156156
@@ -166,36 +166,26 @@ def __init__(
166166 self .poll_interval = poll_interval
167167 self .timeout_seconds = workflow .timeout_minutes * 60
168168
169- update_workflow_status = UpdateWorkflowStatus (
170- "Update Workflow Status " ,
169+ update_workflow_status = UpdateWorkflowStatusUntilCompletion (
170+ "Update status until completion " ,
171171 workflow ,
172172 github_client ,
173173 package_meta ,
174174 log_prefix = log_prefix ,
175+ timeout_seconds = self .timeout_seconds ,
176+ poll_interval = self .poll_interval ,
175177 )
176- update_workflow_status_with_pause = Sequence (
177- "Update Workflow Status with Pause" ,
178- memory = True ,
179- children = [
180- Sleep ("Sleep" , self .poll_interval , log_prefix = log_prefix ),
181- update_workflow_status ,
182- ],
183- )
184-
185178 super ().__init__ (
186179 None ,
187- Timeout (
188- f"Timeout { workflow .timeout_minutes } m" ,
189- Repeat ("Repeat" , update_workflow_status_with_pause , - 1 ),
190- self .timeout_seconds ,
191- ),
180+ update_workflow_status ,
192181 workflow .ephemeral ,
193- "timed_out" ,
182+ "wait_for_completion" ,
183+ "wait_for_completion_message" ,
194184 log_prefix = log_prefix ,
195185 )
196186
197187
198- class TriggerWorkflowGuarded (FlagGuard ):
188+ class TriggerWorkflowGuarded (StatusFlagGuard ):
199189 def __init__ (
200190 self ,
201191 name : str ,
@@ -217,12 +207,12 @@ def __init__(
217207 None if name == "" else name ,
218208 trigger_workflow ,
219209 workflow .ephemeral ,
220- "trigger_failed " ,
210+ "trigger_workflow " ,
221211 log_prefix = log_prefix ,
222212 )
223213
224214
225- class IdentifyTargetRefGuarded (FlagGuard ):
215+ class IdentifyTargetRefGuarded (StatusFlagGuard ):
226216 def __init__ (
227217 self ,
228218 name : str ,
@@ -241,12 +231,12 @@ def __init__(
241231 log_prefix = log_prefix ,
242232 ),
243233 package_meta .ephemeral ,
244- "identify_ref_failed " ,
234+ "identify_ref " ,
245235 log_prefix = log_prefix ,
246236 )
247237
248238
249- class DownloadArtifactsListGuarded (FlagGuard ):
239+ class DownloadArtifactsListGuarded (StatusFlagGuard ):
250240 def __init__ (
251241 self ,
252242 name : str ,
@@ -265,12 +255,12 @@ def __init__(
265255 log_prefix = log_prefix ,
266256 ),
267257 workflow .ephemeral ,
268- "artifacts_download_failed " ,
258+ "download_artifacts " ,
269259 log_prefix = log_prefix ,
270260 )
271261
272262
273- class ExtractArtifactResultGuarded (FlagGuard ):
263+ class ExtractArtifactResultGuarded (StatusFlagGuard ):
274264 def __init__ (
275265 self ,
276266 name : str ,
@@ -291,7 +281,7 @@ def __init__(
291281 log_prefix = log_prefix ,
292282 ),
293283 workflow .ephemeral ,
294- "extract_result_failed " ,
284+ "extract_artifact_result " ,
295285 log_prefix = log_prefix ,
296286 )
297287
@@ -326,7 +316,7 @@ def __init__(
326316 )
327317
328318
329- class RestartPackageGuarded (FlagGuard ):
319+ class RestartPackageGuarded (ConditionGuard ):
330320 """
331321 Reset package if we didn't trigger the workflow in current run
332322 This is intended to be used for build workflow since if build has failed
@@ -353,29 +343,18 @@ def __init__(
353343 reset_package_state_running = SuccessIsRunning (
354344 "Success is Running" , reset_package_state
355345 )
356- reset_package_state_guarded = FlagGuard (
357- None if name == "" else name ,
358- reset_package_state_running ,
359- package .meta .ephemeral ,
360- "identify_ref_failed" ,
361- flag_value = True ,
362- raise_on = [],
363- guard_status = Status .FAILURE ,
364- log_prefix = log_prefix ,
365- )
346+
366347 super ().__init__ (
367- None if name == "" else name ,
368- reset_package_state_guarded ,
369- workflow .ephemeral ,
370- "trigger_attempted" ,
371- flag_value = True ,
372- raise_on = [],
348+ name ,
349+ condition = lambda : workflow .ephemeral .trigger_workflow is not None
350+ or package .meta .ref is None ,
351+ child = reset_package_state_running ,
373352 guard_status = Status .FAILURE ,
374353 log_prefix = log_prefix ,
375354 )
376355
377356
378- class RestartWorkflowGuarded (FlagGuard ):
357+ class RestartWorkflowGuarded (ConditionGuard ):
379358 """
380359 Reset workflow if we didn't trigger the workflow in current run and if there was no identify target ref error
381360
@@ -401,23 +380,12 @@ def __init__(
401380 reset_workflow_state_running = SuccessIsRunning (
402381 "Success is Running" , reset_workflow_state
403382 )
404- reset_workflow_state_guarded = FlagGuard (
405- None if name == "" else name ,
406- reset_workflow_state_running ,
407- package_meta .ephemeral ,
408- "identify_ref_failed" ,
409- flag_value = True ,
410- raise_on = [],
411- guard_status = Status .FAILURE ,
412- log_prefix = log_prefix ,
413- )
383+
414384 super ().__init__ (
415- None if name == "" else name ,
416- reset_workflow_state_guarded ,
417- workflow .ephemeral ,
418- "trigger_attempted" ,
419- flag_value = True ,
420- raise_on = [],
385+ name ,
386+ condition = lambda : workflow .ephemeral .trigger_workflow is not None
387+ or package_meta .ref is None ,
388+ child = reset_workflow_state_running ,
421389 guard_status = Status .FAILURE ,
422390 log_prefix = log_prefix ,
423391 )
0 commit comments