Affinity
You can add the affinity attribute in a task or in a workflow definition to run a specific task on the same workstation where the main task runs or vice versa. The option is useful when you have pool workstations and want to run tasks on the same workstation.
Overview
When you run a task on pools, the workstation is selected dynamically. In such scenarios, you can use the affinity option to run multiple tasks on the same workstation. You can add a task in the main task or workflow definition as a value for the affinity attribute. When either the main task or the affinity task is complete based on priorities or dependencies, the other task runs on the same workstation.
The main task and the affinity task must be in the same workflow. If the workstation for the main task is a dynamic agent, then the workstation for the affinity task must also be the same dynamic agent. If the workstation type for the main task is a pool, then the workstation for the affinity task must be either the same pool or a member of the same pool. If any of these conditions does not match, the task submitted first waits for ten minutes1 and then fails.
- 1 By default, the task waits for ten minutes
if the conditions described above are not met. To customize this time
period, add the UNO_WAITING_JOB_EXPIRE_TIMEOUT
parameter as an environment variable in the
values.yaml file with a value in either seconds
or minutes.
The conditions are monitored every sixty seconds by default. To customize this value, add the UNO_WAITING_JOB_EXPIRE_FREQUENCY parameter as an environment variable in the values.yaml file with a value in either seconds or minutes.
You can add the affinity option either in the main task definition or within the workflow definition that contains the main task. If you add the option in both, then the priority is always given to the one added in the workflow definition. The affinity option specified within the task definition is ignored in this scenario.
-
To add JOB2 (with workstation /WS_AGT_0, a member of the pool delta_pool) as an affinity task in TASKDEF_1 with both tasks in the same workflow, create the task definition for TASKDEF_1 as follows:
--- kind: JobDefinition def: workstation: "delta_pool" folder: "/" name: TASKDEF_1 description: Sample executable task definition TASKDEF_1 type: executable task: executable: interactive: 'false' script: sleep 20 affinity: TASK2 recovery: action: STOP repeatAffinity: falseBoth tasks TASK2 and TASKDEF_1 run sequentially on the /WS_AGT_0 workstation. The order of task submission is based on other factors such as limit, priority, fence, and dependencies allotted to each task.
-
To add TASKDEF (with workstation as the pool delta_pool) as an affinity task in TASK1 (with workstation /WS_AGT_1, a member of the pool delta_pool), create the task definition for TASK1 as follows:
--- kind: JobDefinition def: workstation: /WS_AGT_1 folder: / name: TASK1 type: executable task: executable: interactive: false path: ls credential: {} affinity: TASKDEF recovery: action: STOP repeatAffinity: falseBoth tasks TASK1 and TASKDEF run sequentially on the /WS_AGT_1 workstation. The order of task submission is based on other factors such as limit, priority, fence, and dependencies allotted to each task.
- To add the affinity option in an embedded task definition, create the workflow definition as follows:
--- kind: JobStream def: folder: / name: JS workstation: /WS_AGT_0 jobs: - name: JD1 workstation: /WS_AGT_0 jobDefinition: type: executable task: executable: interactive: false path: ls recovery: action: STOP repeatAffinity: false priority: 10 affinity: TASK2