|
3 | 3 | module Temporalio |
4 | 4 | class Worker |
5 | 5 | # Base class for poller behaviors that control how polling scales. |
6 | | - # |
7 | | - # Use factory methods {.simple_maximum} or {.autoscaling} to create instances. |
8 | 6 | class PollerBehavior |
9 | | - # Creates a simple maximum poller behavior |
10 | | - # The poller will attempt to poll as long as a slot is available, up to the |
11 | | - # provided maximum. Cannot be less than two for workflow tasks, or one for other tasks. |
12 | | - # |
13 | | - # @param maximum [Integer] Maximum number of concurrent poll requests. |
14 | | - # @return [SimpleMaximumPollerBehavior] A simple maximum poller behavior |
15 | | - def self.simple_maximum(maximum = 5) |
16 | | - SimpleMaximumPollerBehavior.new(maximum: maximum) |
17 | | - end |
18 | | - |
19 | | - # Creates an autoscaling poller behavior |
20 | | - # The poller will automatically scale the number of pollers based on feedback |
21 | | - # from the server. A slot must be available before beginning polling. |
22 | | - # |
23 | | - # @param minimum [Integer] Minimum number of poll calls (assuming slots are available). |
24 | | - # @param maximum [Integer] Maximum number of poll calls that will ever be open at once. |
25 | | - # @param initial [Integer] Number of polls attempted initially before scaling kicks in. |
26 | | - # @return [AutoscalingPollerBehavior] An autoscaling poller behavior |
27 | | - def self.autoscaling(minimum: 1, maximum: 100, initial: 5) |
28 | | - AutoscalingPollerBehavior.new(minimum: minimum, maximum: maximum, initial: initial) |
29 | | - end |
30 | | - |
31 | 7 | # @!visibility private |
32 | 8 | def _to_bridge_options |
33 | 9 | raise NotImplementedError, 'Subclasses must implement this method' |
34 | 10 | end |
35 | | - end |
36 | | - |
37 | | - # A poller behavior that attempts to poll as long as a slot is available, up to the |
38 | | - # provided maximum. Cannot be less than two for workflow tasks, or one for other tasks. |
39 | | - class SimpleMaximumPollerBehavior < PollerBehavior |
40 | | - # @return [Integer] Maximum number of concurrent poll requests. |
41 | | - attr_reader :maximum |
42 | | - |
43 | | - # @param maximum [Integer] Maximum number of concurrent poll requests. |
44 | | - def initialize(maximum: 5) |
45 | | - super() |
46 | | - @maximum = maximum |
47 | | - end |
48 | 11 |
|
49 | | - # @!visibility private |
50 | | - def _to_bridge_options |
51 | | - Internal::Bridge::Worker::PollerBehaviorSimpleMaximum.new(simple_maximum: maximum) |
52 | | - end |
53 | | - end |
54 | | - |
55 | | - # A poller behavior that automatically scales the number of pollers based on feedback |
56 | | - # from the server. A slot must be available before beginning polling. |
57 | | - class AutoscalingPollerBehavior < PollerBehavior |
58 | | - # @return [Integer] Minimum number of poll calls (assuming slots are available). |
59 | | - attr_reader :minimum |
60 | | - # @return [Integer] Maximum number of poll calls that will ever be open at once. |
61 | | - attr_reader :maximum |
62 | | - # @return [Integer] Number of polls attempted initially before scaling kicks in. |
63 | | - attr_reader :initial |
64 | | - |
65 | | - # @param minimum [Integer] Minimum number of poll calls (assuming slots are available). |
66 | | - # @param maximum [Integer] Maximum number of poll calls that will ever be open at once. |
67 | | - # @param initial [Integer] Number of polls attempted initially before scaling kicks in. |
68 | | - def initialize(minimum: 1, maximum: 100, initial: 5) |
69 | | - super() |
70 | | - @minimum = minimum |
71 | | - @maximum = maximum |
72 | | - @initial = initial |
| 12 | + # A poller behavior that attempts to poll as long as a slot is available, up to the |
| 13 | + # provided maximum. Cannot be less than two for workflow tasks, or one for other tasks. |
| 14 | + class SimpleMaximum < PollerBehavior |
| 15 | + # @return [Integer] Maximum number of concurrent poll requests. |
| 16 | + attr_reader :maximum |
| 17 | + |
| 18 | + # @param maximum [Integer] Maximum number of concurrent poll requests. |
| 19 | + def initialize(maximum: 5) |
| 20 | + super() |
| 21 | + @maximum = maximum |
| 22 | + end |
| 23 | + |
| 24 | + # @!visibility private |
| 25 | + def _to_bridge_options |
| 26 | + Internal::Bridge::Worker::PollerBehaviorSimpleMaximum.new(simple_maximum: @maximum) |
| 27 | + end |
73 | 28 | end |
74 | 29 |
|
75 | | - # @!visibility private |
76 | | - def _to_bridge_options |
77 | | - Internal::Bridge::Worker::PollerBehaviorAutoscaling.new( |
78 | | - minimum: minimum, |
79 | | - maximum: maximum, |
80 | | - initial: initial |
81 | | - ) |
| 30 | + # A poller behavior that automatically scales the number of pollers based on feedback |
| 31 | + # from the server. A slot must be available before beginning polling. |
| 32 | + class Autoscaling < PollerBehavior |
| 33 | + # @return [Integer] Minimum number of poll calls (assuming slots are available). |
| 34 | + attr_reader :minimum |
| 35 | + # @return [Integer] Maximum number of poll calls that will ever be open at once. |
| 36 | + attr_reader :maximum |
| 37 | + # @return [Integer] Number of polls attempted initially before scaling kicks in. |
| 38 | + attr_reader :initial |
| 39 | + |
| 40 | + # @param minimum [Integer] Minimum number of poll calls (assuming slots are available). |
| 41 | + # @param maximum [Integer] Maximum number of poll calls that will ever be open at once. |
| 42 | + # @param initial [Integer] Number of polls attempted initially before scaling kicks in. |
| 43 | + def initialize(minimum: 1, maximum: 100, initial: 5) |
| 44 | + super() |
| 45 | + @minimum = minimum |
| 46 | + @maximum = maximum |
| 47 | + @initial = initial |
| 48 | + end |
| 49 | + |
| 50 | + # @!visibility private |
| 51 | + def _to_bridge_options |
| 52 | + Internal::Bridge::Worker::PollerBehaviorAutoscaling.new( |
| 53 | + minimum: @minimum, |
| 54 | + maximum: @maximum, |
| 55 | + initial: @initial |
| 56 | + ) |
| 57 | + end |
82 | 58 | end |
83 | 59 | end |
84 | 60 | end |
|
0 commit comments