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

Inherits:
SlotSupplier
  • Object
show all
Defined in:
lib/temporalio/worker/tuner.rb

Overview

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 Classes: MarkUsedContext, ReleaseContext, ReserveContext

Instance Method Summary collapse

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)


162
163
164
# File 'lib/temporalio/worker/tuner.rb', line 162

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)


173
174
175
# File 'lib/temporalio/worker/tuner.rb', line 173

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)


133
134
135
# File 'lib/temporalio/worker/tuner.rb', line 133

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)


148
149
150
# File 'lib/temporalio/worker/tuner.rb', line 148

def try_reserve_slot(context)
  raise NotImplementedError
end