Class: Temporalio::Worker::Tuner::SlotSupplier::Custom
- Inherits:
-
Temporalio::Worker::Tuner::SlotSupplier
- Object
- Temporalio::Worker::Tuner::SlotSupplier
- Temporalio::Worker::Tuner::SlotSupplier::Custom
- Defined in:
- lib/temporalio/worker/tuner.rb
Overview
WARNING: This API is experimental.
A slot supplier that has callbacks invoked to handle slot supplying.
Users should be cautious when implementing this and make sure it is heavily tested and the documentation for every method is well understood.
Defined Under Namespace
Modules: SlotInfo
Constant Summary collapse
- ReserveContext =
Context provided for slot reservation on custom slot supplier.
Data.define( :slot_type, :task_queue, :worker_identity, :worker_deployment_name, :worker_build_id, :sticky? )
- MarkUsedContext =
Context provided for marking a slot used.
Data.define( :slot_info, :permit )
- ReleaseContext =
Context provided for releasing a slot.
Data.define( :slot_info, :permit )
Instance Attribute Summary collapse
-
#permit ⇒ Object
Object that was provided as the permit on reserve.
-
#slot_info ⇒ SlotInfo::Workflow, ...
Information about the slot.
-
#slot_type ⇒ :workflow, ...
Slot type.
-
#sticky? ⇒ Boolean
True if this reservation is for a sticky workflow task.
-
#task_queue ⇒ String
Task queue.
-
#worker_build_id ⇒ String
Worker build ID or empty string if not applicable.
-
#worker_deployment_name ⇒ String
Worker deployment name or empty string if not applicable.
-
#worker_identity ⇒ String
Worker identity.
Instance Method Summary collapse
-
#mark_slot_used(context) ⇒ Object
Mark a slot as used.
-
#release_slot(context) ⇒ Object
Release a previously reserved slot.
-
#reserve_slot(context, cancellation) {|Object| ... } ⇒ Object
Reserve a slot.
-
#try_reserve_slot(context) ⇒ Object?
Try to reserve a slot.
Instance Attribute Details
#permit ⇒ Object
Returns Object that was provided as the permit on reserve.
102 103 104 105 |
# File 'lib/temporalio/worker/tuner.rb', line 102 MarkUsedContext = Data.define( :slot_info, :permit ) |
#slot_info ⇒ SlotInfo::Workflow, ...
Returns Information about the slot. This may be nil if the slot was never used.
102 103 104 105 |
# File 'lib/temporalio/worker/tuner.rb', line 102 MarkUsedContext = Data.define( :slot_info, :permit ) |
#slot_type ⇒ :workflow, ...
Returns Slot type.
86 87 88 89 90 91 92 93 |
# File 'lib/temporalio/worker/tuner.rb', line 86 ReserveContext = Data.define( :slot_type, :task_queue, :worker_identity, :worker_deployment_name, :worker_build_id, :sticky? ) |
#sticky? ⇒ Boolean
Returns True if this reservation is for a sticky workflow task.
86 87 88 89 90 91 92 93 |
# File 'lib/temporalio/worker/tuner.rb', line 86 ReserveContext = Data.define( :slot_type, :task_queue, :worker_identity, :worker_deployment_name, :worker_build_id, :sticky? ) |
#task_queue ⇒ String
Returns Task queue.
86 87 88 89 90 91 92 93 |
# File 'lib/temporalio/worker/tuner.rb', line 86 ReserveContext = Data.define( :slot_type, :task_queue, :worker_identity, :worker_deployment_name, :worker_build_id, :sticky? ) |
#worker_build_id ⇒ String
Returns Worker build ID or empty string if not applicable.
86 87 88 89 90 91 92 93 |
# File 'lib/temporalio/worker/tuner.rb', line 86 ReserveContext = Data.define( :slot_type, :task_queue, :worker_identity, :worker_deployment_name, :worker_build_id, :sticky? ) |
#worker_deployment_name ⇒ String
Returns Worker deployment name or empty string if not applicable.
86 87 88 89 90 91 92 93 |
# File 'lib/temporalio/worker/tuner.rb', line 86 ReserveContext = Data.define( :slot_type, :task_queue, :worker_identity, :worker_deployment_name, :worker_build_id, :sticky? ) |
#worker_identity ⇒ String
Returns Worker identity.
86 87 88 89 90 91 92 93 |
# File 'lib/temporalio/worker/tuner.rb', line 86 ReserveContext = Data.define( :slot_type, :task_queue, :worker_identity, :worker_deployment_name, :worker_build_id, :sticky? ) |
Instance Method Details
#mark_slot_used(context) ⇒ Object
WARNING: This should never block, this should return immediately.
WARNING: This call should never raise an exception. Any exception raised is ignored.
Mark a slot as used.
Due to the nature of Temporal polling, slots are reserved before they are used and may never get used. This call is made as just a notification when a slot is actually used.
166 167 168 |
# File 'lib/temporalio/worker/tuner.rb', line 166 def mark_slot_used(context) raise NotImplementedError end |
#release_slot(context) ⇒ Object
WARNING: This should never block, this should return immediately.
WARNING: This call should never raise an exception. Any exception raised is ignored.
Release a previously reserved slot.
177 178 179 |
# File 'lib/temporalio/worker/tuner.rb', line 177 def release_slot(context) raise NotImplementedError end |
#reserve_slot(context, cancellation) {|Object| ... } ⇒ Object
WARNING: This call should never raise an exception. Any exception raised is ignored and this is called again after 1 second.
Reserve a slot.
This can/should block and must provide the permit to the (code) block. The permit is any object (including nil) that will be given on the context for mark_slot_used and release_slot.
Just returning from this call is not enough to reserve the slot, a permit must be provided to the block (e.g. via yield or block.call). If the call completes, the system will still wait on the block (so this can be backgrounded by passing the block to something else). Reservations may be canceled via the given cancellation. Users can do things like add_cancel_callback, but it is very important that the code in the callback is fast as it is run on the same reactor thread as many other Temporal Ruby worker calls.
137 138 139 |
# File 'lib/temporalio/worker/tuner.rb', line 137 def reserve_slot(context, cancellation, &) raise NotImplementedError end |
#try_reserve_slot(context) ⇒ Object?
WARNING: This should never block, this should return immediately with a permit, or nil if the reservation could not occur.
WARNING: This call should never raise an exception. Any exception raised is ignored and the slot reservation attempt fails (i.e. same as if this method returned nil).
Try to reserve a slot.
152 153 154 |
# File 'lib/temporalio/worker/tuner.rb', line 152 def try_reserve_slot(context) raise NotImplementedError end |