@@ -469,18 +469,66 @@ def check_metrics(self, job):
469469
470470 # And check against the condition
471471 if trigger .should_trigger (value ):
472- self .trigger_workflow_action (trigger . action . name )
472+ self .trigger_workflow_action (trigger , step_name , value )
473473
474- def trigger_workflow_action (self , action_name ):
474+ def trigger_grow (self , trigger , step_name , value ):
475+ """
476+ Trigger the job to grow
477+ """
478+ previous = self .workflow .jobs [step_name ]["config" ]["nnodes" ]
479+ max_size = trigger .action .max_size
480+ if max_size >= previous + 1 :
481+ LOGGER .info (
482+ f"Grow triggered: { trigger .action .metric } { trigger .when } ({ value } ), already >= max size { max_size } "
483+ )
484+ return
485+
486+ self .workflow .jobs [step_name ]["config" ]["nnodes" ] += 1
487+ updated = self .workflow .jobs [step_name ]["config" ]["nnodes" ]
488+ LOGGER .info (
489+ f"Grow triggered: { trigger .action .metric } { trigger .when } ({ value } ), nodes { previous } =>{ updated } "
490+ )
491+
492+ def trigger_shrink (self , trigger , step_name , value ):
493+ """
494+ Trigger the job to shrink, down to a min size of 1
495+ """
496+ previous = self .workflow .jobs [step_name ]["config" ]["nnodes" ]
497+ min_size = trigger .action .min_size or 1
498+ if previous <= min_size :
499+ LOGGER .info (
500+ f"Shrink triggered: { trigger .action .metric } { trigger .when } ({ value } ), already at min size { min_size } "
501+ )
502+ return
503+ self .workflow .jobs [step_name ]["config" ]["nnodes" ] -= 1
504+ updated = self .workflow .jobs [step_name ]["config" ]["nnodes" ]
505+ LOGGER .info (
506+ f"Shrink triggered: { trigger .action .metric } { trigger .when } ({ value } ), nodes { previous } =>{ updated } "
507+ )
508+
509+ def trigger_workflow_action (self , trigger , step_name , value ):
475510 """
476511 Given an action name, issue it for the workflow
477512 """
478- if action_name == "finish-workflow" :
513+ # This action has a minimum number of total completions
514+ if trigger .action .min_completions :
515+ completions = len (self .get_current_state ()["completed" ])
516+ if completions < trigger .action .min_completions :
517+ return
518+
519+ # Check if we have enough completions
520+ if trigger .action .name == "finish-workflow" :
479521 # TODO: add more detail in calling function to event trigger
480- LOGGER .info ("Workflow completion triggered, ending workflow." )
522+ LOGGER .info (
523+ f"Workflow completion triggered: { trigger .action .metric } { trigger .when } ({ value } )"
524+ )
481525 self .complete_workflow ()
482526
483- # TODO add support for grow, shrink
527+ if trigger .action .name == "grow" :
528+ self .trigger_grow (trigger , step_name , value )
529+
530+ if trigger .action .name == "shrink" :
531+ self .trigger_shrink (trigger , step_name , value )
484532
485533 def update_metrics (self , job ):
486534 """
@@ -495,7 +543,7 @@ def update_metrics(self, job):
495543 # Add job duration if supported by tracker
496544 duration = job .duration ()
497545 if job .is_completed () and duration is not None :
498- self .metrics .add_model_entry ("duration" , duration )
546+ self .metrics .add_model_entry ("duration" , duration , step = job . step_name )
499547
500548 def add_timestamp_first_seen (self , label ):
501549 """
0 commit comments