Skip to content

Commit 7170f15

Browse files
committed
feat: Add priority fairness field
1 parent 23f57a5 commit 7170f15

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

src/Common/Priority.php

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* For all fields, the field not present or equal to zero/empty string means to inherit the value
2525
* from the calling workflow, or if there is no calling workflow, then use the default value.
2626
*
27+
* @see \Temporal\Api\Common\V1\Priority
28+
*
2729
* @internal The feature is experimental and may change in the future.
2830
*/
2931
final class Priority
@@ -45,6 +47,36 @@ final class Priority
4547
#[Marshal(name: 'PriorityKey')]
4648
public int $priorityKey = 0;
4749

50+
/**
51+
* FairnessKey is a short string that's used as a key for a fairness
52+
* balancing mechanism. It may correspond to a tenant id, or to a fixed
53+
* string like "high" or "low". The default is the empty string.
54+
*
55+
* The fairness mechanism attempts to dispatch tasks for a given key in
56+
* proportion to its weight. For example, using a thousand distinct tenant
57+
* ids, each with a weight of 1.0 (the default) will result in each tenant
58+
* getting a roughly equal share of task dispatch throughput.
59+
*
60+
* Fairness keys are limited to 64 bytes.
61+
*/
62+
#[Marshal(name: 'fairness_key')]
63+
#[Marshal(name: 'FairnessKey')]
64+
public string $fairnessKey = '';
65+
66+
/**
67+
* FairnessWeight for a task can come from multiple sources for
68+
* flexibility. From highest to lowest precedence:
69+
* 1. Weights for a small set of keys can be overridden in task queue
70+
* configuration with an API.
71+
* 2. It can be attached to the workflow/activity in this field.
72+
* 3. The default weight of 1.0 will be used.
73+
*
74+
* Weight values are clamped to the range [0.001, 1000].
75+
*/
76+
#[Marshal(name: 'fairness_weight')]
77+
#[Marshal(name: 'FairnessWeight')]
78+
public float $fairnessWeight = 0.0;
79+
4880
/**
4981
* @param int<0, max> $priorityKey
5082
*/
@@ -76,12 +108,50 @@ public function withPriorityKey(int $value): self
76108
return $clone;
77109
}
78110

111+
/**
112+
* FairnessKey is a short string that's used as a key for a fairness
113+
* balancing mechanism. It may correspond to a tenant id, or to a fixed
114+
* string like "high" or "low". The default is the empty string.
115+
*
116+
* @return $this
117+
*/
118+
public function withFairnessKey(string $value): self
119+
{
120+
$clone = clone $this;
121+
$clone->fairnessKey = $value;
122+
return $clone;
123+
}
124+
125+
/**
126+
* FairnessWeight for a task can come from multiple sources for
127+
* flexibility. From highest to lowest precedence:
128+
* 1. Weights for a small set of keys can be overridden in task queue
129+
* configuration with an API.
130+
* 2. It can be attached to the workflow/activity in this field.
131+
* 3. The default weight of 1.0 will be used.
132+
*
133+
* Weight values are clamped to the range [0.001, 1000].
134+
*
135+
* @return $this
136+
*/
137+
public function withFairnessWeight(float $value): self
138+
{
139+
$value < 0.001 or $value > 1000.0 and throw new \InvalidArgumentException(
140+
'FairnessWeight must be in the range [0.001, 1000].',
141+
);
142+
$clone = clone $this;
143+
$clone->fairnessWeight = $value;
144+
return $clone;
145+
}
146+
79147
/**
80148
* @internal for internal use only
81149
*/
82150
public function toProto(): \Temporal\Api\Common\V1\Priority
83151
{
84152
return (new \Temporal\Api\Common\V1\Priority())
85-
->setPriorityKey($this->priorityKey);
153+
->setPriorityKey($this->priorityKey)
154+
->setFairnessKey($this->fairnessKey)
155+
->setFairnessWeight($this->fairnessWeight);
86156
}
87157
}

0 commit comments

Comments
 (0)