Repository navigation
Expand file tree
/
Copy pathpriority.go
More file actions
64 lines (56 loc) · 1.52 KB
/
Copy pathpriority.go
File metadata and controls
64 lines (56 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
59
60
61
62
63
64
package gush
import "unicode/utf8"
// maxFairKeyBytes is the longest fairness key the Temporal server accepts.
const maxFairKeyBytes = 64
// Priority is the scheduling priority of a flow or step. Higher priority runs first.
type Priority string
const (
PriorityUrgent Priority = "urgent"
PriorityHigh Priority = "high"
PriorityMedium Priority = "medium" // default
PriorityLow Priority = "low"
PriorityTrivial Priority = "trivial"
)
// Int returns the Temporal priority key, from 1 for PriorityUrgent to 5 for
// PriorityTrivial. An unknown priority counts as PriorityMedium.
func (priority Priority) Int() int {
switch priority {
case PriorityUrgent:
return 1
case PriorityHigh:
return 2
case PriorityLow:
return 4
case PriorityTrivial:
return 5
}
return 3
}
// NewPriority converts a Temporal priority key back to a Priority. An unknown key
// counts as PriorityMedium.
func NewPriority(key int) Priority {
switch key {
case 1:
return PriorityUrgent
case 2:
return PriorityHigh
case 4:
return PriorityLow
case 5:
return PriorityTrivial
}
return PriorityMedium
}
// truncateFairKey cuts key to the length the server accepts, because a longer key fails
// the whole flow start or command rather than only losing fairness. It cuts between
// characters, since a string holding half a character cannot be marshaled.
func truncateFairKey(key string) string {
if len(key) <= maxFairKeyBytes {
return key
}
end := maxFairKeyBytes
for end > 0 && !utf8.RuneStart(key[end]) {
end--
}
return key[:end]
}