Affinity attribute

Use the Affinity attribute in a task or workflow definition to ensure that multiple tasks run on the same workstation.

Overview

When you run a task on a pool, the workstation is selected dynamically. In such scenarios, you can use the Affinity option to run multiple tasks on the same workstation. You add a task in the main task or in a workflow definition as a value for the Affinity attribute. When either the main task or the affinity task completes 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, the workstation for the affinity task must also be the same dynamic agent.
  • If the workstation type for the main task is a pool, the workstation for the affinity task must be either the same pool or a member of the same pool.
If any of these conditions are not met, the task submitted first waits for ten minutes1 and then fails.
If the workstation for the main task or the affinity task is initially not a member of the pool, you can add it to the pool within ten minutes1 to run the task on the same workstation where the other task runs.
Note:
  • 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 specify multiple entries for the Affinity field. The system processes the request against the available resources based on the specified quantity for each entry.

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 locations, the option specified in the workflow definition always takes priority. The affinity option specified within the task definition is ignored in this scenario.

For embedded tasks, you must add the Affinity option either within the embedded task definition or within the workflow definition. If you add the option in both locations, the workflow definition is not saved and returns an error.

Examples:
  1. 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: false

    Both 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.

  2. 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: false

    Both 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.

  3. 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