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

Constructor Details

#initialize(priority_key: nil, fairness_key: nil, fairness_weight: nil) ⇒ Priority

Initialize a new Priority instance.

Parameters:

  • priority_key (Integer, nil) (defaults to: nil)

    The priority key

  • fairness_key (String, nil) (defaults to: nil)

    The fairness key

  • fairness_weight (Float, nil) (defaults to: nil)

    The fairness weight



80
81
82
# File 'lib/temporalio/priority.rb', line 80

def initialize(priority_key: nil, fairness_key: nil, fairness_weight: nil)
  super
end

Instance Attribute Details

#fairness_keyString?

Returns FairnessKey is a short string that’s used as a key for a fairness balancing mechanism. It may correspond to a tenant id, or to a fixed string like “high” or “low”. The default is the empty string.

The fairness mechanism attempts to dispatch tasks for a given key in proportion to its weight. For example, using a thousand distinct tenant ids, each with a weight of 1.0 (the default) will result in each tenant getting a roughly equal share of task dispatch throughput.

Fairness keys are limited to 64 bytes.

Returns:

  • (String, nil)

    FairnessKey is a short string that’s used as a key for a fairness balancing mechanism. It may correspond to a tenant id, or to a fixed string like “high” or “low”. The default is the empty string.

    The fairness mechanism attempts to dispatch tasks for a given key in proportion to its weight. For example, using a thousand distinct tenant ids, each with a weight of 1.0 (the default) will result in each tenant getting a roughly equal share of task dispatch throughput.

    Fairness keys are limited to 64 bytes.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/temporalio/priority.rb', line 56

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,
      fairness_key: priority.fairness_key.empty? ? nil : priority.fairness_key,
      fairness_weight: priority.fairness_weight.zero? ? nil : priority.fairness_weight
    )
  end

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

  # Initialize a new Priority instance.
  #
  # @param priority_key [Integer, nil] The priority key
  # @param fairness_key [String, nil] The fairness key
  # @param fairness_weight [Float, nil] The fairness weight
  def initialize(priority_key: nil, fairness_key: nil, fairness_weight: nil)
    super
  end

  # @!visibility private
  def _to_proto
    return nil if empty?

    Temporalio::Api::Common::V1::Priority.new(
      priority_key: priority_key || 0,
      fairness_key: fairness_key || '',
      fairness_weight: fairness_weight || 0.0
    )
  end

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

#fairness_weightFloat?

Returns Weight for a task can come from multiple sources for flexibility. From highest to lowest precedence:

  1. Weights for a small set of keys can be overridden in task queue configuration with an API.

  2. It can be attached to the workflow/activity in this field.

  3. The default fairness_weight of 1.0 will be used.

Weight values are clamped to the range [0.001, 1000].

Returns:

  • (Float, nil)

    Weight for a task can come from multiple sources for flexibility. From highest to lowest precedence:

    1. Weights for a small set of keys can be overridden in task queue configuration with an API.

    2. It can be attached to the workflow/activity in this field.

    3. The default fairness_weight of 1.0 will be used.

    Weight values are clamped to the range [0.001, 1000].



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/temporalio/priority.rb', line 56

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,
      fairness_key: priority.fairness_key.empty? ? nil : priority.fairness_key,
      fairness_weight: priority.fairness_weight.zero? ? nil : priority.fairness_weight
    )
  end

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

  # Initialize a new Priority instance.
  #
  # @param priority_key [Integer, nil] The priority key
  # @param fairness_key [String, nil] The fairness key
  # @param fairness_weight [Float, nil] The fairness weight
  def initialize(priority_key: nil, fairness_key: nil, fairness_weight: nil)
    super
  end

  # @!visibility private
  def _to_proto
    return nil if empty?

    Temporalio::Api::Common::V1::Priority.new(
      priority_key: priority_key || 0,
      fairness_key: fairness_key || '',
      fairness_weight: fairness_weight || 0.0
    )
  end

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

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



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/temporalio/priority.rb', line 56

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,
      fairness_key: priority.fairness_key.empty? ? nil : priority.fairness_key,
      fairness_weight: priority.fairness_weight.zero? ? nil : priority.fairness_weight
    )
  end

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

  # Initialize a new Priority instance.
  #
  # @param priority_key [Integer, nil] The priority key
  # @param fairness_key [String, nil] The fairness key
  # @param fairness_weight [Float, nil] The fairness weight
  def initialize(priority_key: nil, fairness_key: nil, fairness_weight: nil)
    super
  end

  # @!visibility private
  def _to_proto
    return nil if empty?

    Temporalio::Api::Common::V1::Priority.new(
      priority_key: priority_key || 0,
      fairness_key: fairness_key || '',
      fairness_weight: fairness_weight || 0.0
    )
  end

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

Class Method Details

.defaultPriority

The default priority instance.

Returns:



71
72
73
# File 'lib/temporalio/priority.rb', line 71

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

Instance Method Details

#empty?Boolean

Returns True if this priority is empty/default.

Returns:

  • (Boolean)

    True if this priority is empty/default



96
97
98
# File 'lib/temporalio/priority.rb', line 96

def empty?
  priority_key.nil? && fairness_key.nil? && fairness_weight.nil?
end