class CustomSlotSupplier(ABC): (source)
This class can be implemented to provide custom slot supplier behavior.
Warning
Custom slot suppliers are currently experimental.
Method | mark |
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 |
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 |
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 |
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... |
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:SlotMarkUsedContext | The context for marking a slot as used. |
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:SlotReleaseContext | The context for releasing a 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.
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:SlotReserveContext | The context for slot reservation. |
Returns | |
SlotPermit | A permit to use the slot which may be populated with your own data. |
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:SlotReserveContext | The context for slot reservation. |
Returns | |
Optional[ | Maybe a permit to use the slot which may be populated with your own data. |