class documentation

class CustomSlotSupplier(ABC): (source)

View In Hierarchy

This class can be implemented to provide custom slot supplier behavior.

Warning

Custom slot suppliers are currently experimental.

Method mark_slot_used This function is called once a slot is actually being used to process some task, which may be some time after the slot was reserved originally. For example, if there is no work for a worker, a number of slots equal to the number of active pollers may already be reserved, but none of them are being used yet...
Method release_slot This function is called once a permit is no longer needed. This could be because the task has finished, whether successfully or not, or because the slot was no longer needed (ex: the number of active pollers decreased)...
Async Method reserve_slot This function is called before polling for new tasks. Your implementation must block until a slot is available then return a permit to use that slot.
Method try_reserve_slot This function is called when trying to reserve slots for "eager" workflow and activity tasks. Eager tasks are those which are returned as a result of completing a workflow task, rather than from polling...
@abstractmethod
def mark_slot_used(self, ctx: SlotMarkUsedContext): (source)

This function is called once a slot is actually being used to process some task, which may be some time after the slot was reserved originally. For example, if there is no work for a worker, a number of slots equal to the number of active pollers may already be reserved, but none of them are being used yet. This call should be non-blocking.

Parameters
ctx:SlotMarkUsedContextThe context for marking a slot as used.
@abstractmethod
def release_slot(self, ctx: SlotReleaseContext): (source)

This function is called once a permit is no longer needed. This could be because the task has finished, whether successfully or not, or because the slot was no longer needed (ex: the number of active pollers decreased). This call should be non-blocking.

Parameters
ctx:SlotReleaseContextThe context for releasing a slot.
@abstractmethod
async def reserve_slot(self, ctx: SlotReserveContext) -> SlotPermit: (source)

This function is called before polling for new tasks. Your implementation must block until a slot is available then return a permit to use that slot.

The only acceptable exception to throw is asyncio.CancelledError, as invocations of this method may be cancelled. Any other exceptions thrown will be logged and ignored.

It is technically possible but rare, during worker shutdown, for this method to be called and return a value, but the Rust Core may not have a chance to _observe_ that value. In such cases the returned permit will not be released. The permit will, however, be forgotten and python will garbage collect it. So if you use the same slot supplier over the lifetime of more than one worker and it is critically important for you to clean up some resources associated all permits you construct, then consider using a finalizer on your returned permits.

Parameters
ctx:SlotReserveContextThe context for slot reservation.
Returns
SlotPermitA permit to use the slot which may be populated with your own data.
@abstractmethod
def try_reserve_slot(self, ctx: SlotReserveContext) -> Optional[SlotPermit]: (source)

This function is called when trying to reserve slots for "eager" workflow and activity tasks. Eager tasks are those which are returned as a result of completing a workflow task, rather than from polling. Your implementation must not block, and if a slot is available, return a permit to use that slot.

Parameters
ctx:SlotReserveContextThe context for slot reservation.
Returns
Optional[SlotPermit]Maybe a permit to use the slot which may be populated with your own data.