Class: Temporalio::Worker::Tuner::SlotSupplier::Custom

Inherits:
Temporalio::Worker::Tuner::SlotSupplier show all
Defined in:
lib/temporalio/worker/tuner.rb

Overview

Note:

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

Instance Method Summary collapse

Instance Attribute Details

#permitObject

Returns Object that was provided as the permit on reserve.

Returns:

  • (Object)

    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_infoSlotInfo::Workflow, ...

Returns Information about the slot. This may be nil if the slot was never used.

Returns:



102
103
104
105
# File 'lib/temporalio/worker/tuner.rb', line 102

MarkUsedContext = Data.define(
  :slot_info,
  :permit
)

#slot_type:workflow, ...

Returns Slot type.

Returns:

  • (:workflow, :activity, :local_activity, :nexus)

    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.

Returns:

  • (Boolean)

    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_queueString

Returns Task queue.

Returns:

  • (String)

    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_idString

Returns Worker build ID or empty string if not applicable.

Returns:

  • (String)

    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_nameString

Returns Worker deployment name or empty string if not applicable.

Returns:

  • (String)

    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_identityString

Returns Worker identity.

Returns:

  • (String)

    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

Note:

WARNING: This should never block, this should return immediately.

Note:

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.

Parameters:

  • context (MarkUsedContext)

    Contextual information about this reserve call.

Raises:

  • (NotImplementedError)


166
167
168
# File 'lib/temporalio/worker/tuner.rb', line 166

def mark_slot_used(context)
  raise NotImplementedError
end

#release_slot(context) ⇒ Object

Note:

WARNING: This should never block, this should return immediately.

Note:

WARNING: This call should never raise an exception. Any exception raised is ignored.

Release a previously reserved slot.

Parameters:

  • context (ReleaseContext)

    Contextual information about this reserve call.

Raises:

  • (NotImplementedError)


177
178
179
# File 'lib/temporalio/worker/tuner.rb', line 177

def release_slot(context)
  raise NotImplementedError
end

#reserve_slot(context, cancellation) {|Object| ... } ⇒ Object

Note:

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.

Parameters:

  • context (ReserveContext)

    Contextual information about this reserve call.

  • cancellation (Cancellation)

    Cancellation that is canceled when the reservation is no longer being asked for.

Yields:

  • (Object)

    Confirm reservation and provide a permit.

Raises:

  • (NotImplementedError)


137
138
139
# File 'lib/temporalio/worker/tuner.rb', line 137

def reserve_slot(context, cancellation, &)
  raise NotImplementedError
end

#try_reserve_slot(context) ⇒ Object?

Note:

WARNING: This should never block, this should return immediately with a permit, or nil if the reservation could not occur.

Note:

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.

Parameters:

  • context (ReserveContext)

    Contextual information about this reserve call.

Returns:

  • (Object, nil)

    A non-nil object to perform the reservation successfully, a nil to fail the reservation.

Raises:

  • (NotImplementedError)


152
153
154
# File 'lib/temporalio/worker/tuner.rb', line 152

def try_reserve_slot(context)
  raise NotImplementedError
end