Setting Task Priority

By default, tasks on a task list are delivered based upon their arrival time: tasks that are scheduled first are run first. By setting an optional task priority, you can give priority to certain tasks: Amazon SWF will attempt to deliver higher-priority tasks on a task list before those with lower priority. Tasks with the same priority are ordered by arrival time.

You can set a task priority for both workflows and activities. A workflow's task priority does not affect the priority of any activity tasks it schedules, nor does it affect any child workflows it starts. The default priority for an activity or workflow is set (either by you or by Amazon SWF) during registration, and the registered task priority is always used unless it is overridden while scheduling the activity or starting a workflow execution.

Task priority values can range from "-2147483648" to "2147483647", with higher numbers indicating higher priority. If you don't set the task priority for an activity or workflow, it will be assigned a priority of zero ("0").

Setting Task Priority for Workflows#

You can set the task priority for a workflow when you register it or start it. The task priority that is set when the workflow type is registered is used as the default for any workflow executions of that type, unless it is overridden when starting the workflow execution.

To register a workflow type with a default task priority, use the default_task_priority option when declaring it:

workflow :priority_workflow do
  {
    default_task_list: "workflow_tasks",
    default_task_priority: 10,
    version: "1.0",
  }
end

You can override a workflow type's registered (default) task priority by setting task_priority when you start the workflow execution:

workflow_client.start_execution() {
  {
    task_list: "workflow_tasks",
    tag_list: [ "lowpriority" ],
    task_priority: -5
  }
}

Setting Task Priority for Activities#

You can set the task priority for an activity either when registering it or when scheduling it. The task priority that is set when registering an activity type is used as the default priority when the activity is run, unless it is overridden when scheduling the activity.

Just as with workflow types, to register an activity type with a default task priority use the default_task_priority option when declaring it:

activity :do_something_important do
{
  version: "1.5",
  default_task_list: "activity_list",
  default_task_priority: 10,
  default_task_schedule_to_start_timeout: 30,
  default_task_start_to_close_timeout: 30
}
end

You can also set the task_priority option for an activity when you schedule it, overriding the registered (default) task priority.

important_activity_client.send_async(
  :do_something_important, { task_priority: 20 } )