Class: Temporalio::Priority

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/priority.rb

Overview

Priority contains metadata that controls relative ordering of task processing when tasks are backlogged in a queue. Initially, Priority will be used in activity and workflow task queues, which are typically where backlogs exist. Priority is (for now) attached to workflows and activities. Activities and child workflows inherit Priority from the workflow that created them, but may override fields when they are started or modified. For each field of a Priority on an activity/workflow, not present or equal to zero/empty string means to inherit the value from the calling workflow, or if there is no calling workflow, then use the default (documented on the field).

The overall semantics of Priority are:

  1. First, consider “priority_key”: lower number goes first.

(more will be added here later).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#priority_keyInteger?

Returns The priority key, which is a positive integer from 1 to n, where smaller integers correspond to higher priorities (tasks run sooner). In general, tasks in a queue should be processed in close to priority order, although small deviations are possible. The maximum priority value (minimum priority) is determined by server configuration, and defaults to 5.

The default priority is (min+max)/2. With the default max of 5 and min of 1, that comes out to 3.

Returns:

  • (Integer, nil)

    The priority key, which is a positive integer from 1 to n, where smaller integers correspond to higher priorities (tasks run sooner). In general, tasks in a queue should be processed in close to priority order, although small deviations are possible. The maximum priority value (minimum priority) is determined by server configuration, and defaults to 5.

    The default priority is (min+max)/2. With the default max of 5 and min of 1, that comes out to 3.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/temporalio/priority.rb', line 32

class Priority
  # @!visibility private
  def self._from_proto(priority)
    return default if priority.nil?

    new(priority_key: priority.priority_key.zero? ? nil : priority.priority_key)
  end

  # The default priority instance.
  #
  # @return [Priority] The default priority
  def self.default
    @default ||= new(priority_key: nil)
  end

  # @!visibility private
  def _to_proto
    return nil if priority_key.nil?

    Temporalio::Api::Common::V1::Priority.new(priority_key: priority_key || 0)
  end

  # @return [Boolean] True if this priority is empty/default
  def empty?
    priority_key.nil?
  end
end

Class Method Details

.defaultPriority

The default priority instance.

Returns:



43
44
45
# File 'lib/temporalio/priority.rb', line 43

def self.default
  @default ||= new(priority_key: nil)
end

Instance Method Details

#empty?Boolean

Returns True if this priority is empty/default.

Returns:

  • (Boolean)

    True if this priority is empty/default



55
56
57
# File 'lib/temporalio/priority.rb', line 55

def empty?
  priority_key.nil?
end