Using Agent groups when adding tasks via STOP_MODIFY
search cancel

Using Agent groups when adding tasks via STOP_MODIFY


Article ID: 255374


Updated On:


CA Automic Workload Automation - Automation Engine CA Automic One Automation


There is a workflow that has a single task in it.  That task use stop_modify on the workflow to stop the workflow at runtime and add the same job 10 times.  The job uses PREP_PROCESS_AGENTGROUP in the Pre-Process and should choose its agent in a round-robin fashion.  Is there a way to get the agent to load balance or round-robin the agent so that half of the jobs inserted into the workflow go to one agent and the other half go to another agent?

Right now, the script in the task that adds jobs looks a bit like this from a high-level/pseudo-code view:

Stop workflow
Loop 10 times with:
   Insert task and info for that task
End loop
Commit changes to workflow
Start workflow

and the jobs aren't split 50/50 between the agents; there doesn't seem to be a rhyme or reason to how they're assigned.


Due to how generation works, the agents do not assign one and then the other.  Instead, they all activate and generate at the same time.


A high-level, pseudo code could look something like:

Loop 10 times with:
    Stop workflow
    Insert task and info for that task
    Wait 1 second
    Commit changes to workflow
    Start workflow
End loop

The loop that stops the workflow and then starts it again each iteration allows the jobs to activate after the workflow starts again and then the hostgroup knows that the agent is being used.  The wait 1 second allows for the activation of the tasks to fully go through and assign an agent before the next iteration.  There's one more part of this which is to make the hostgroup load dependent and to update the jobs to use resources (something like 10) in the attributes tab.  So over all, these are the requirements:

  1. Update the hostgroup to use Type "Load Dependent"
  2. On the Attributes tab for the job, update Consume to "10" resources (this number is arbitrary and can be any number above 0)
  3. The script might look like this:

    :set &job_name# = 'jobs.loopme'
    :set &count# = 0
    :while &count# < 10

    :    set &ret# = modify_task(&$activator_runid#, stop_modify)
    :    set &nr# = modify_task(&$activator_runid#,"&job_name#",, add_task)
    :    set &nr# = format(&nr#)
    :    set &ret# = modify_task(&$activator_runid#,"end",, add_dependency,,&nr#, "any_ok")
    :    set &count# = add(&count#, 1)
    :    wait 1
    :    set &ret# = modify_task(&$activator_runid#, commit)
    :    set &ret# = modify_task(&$activator_runid#, go)

This way using a script like this, the agents should round-robin.