Table of Contents

Class CustomSlotSupplier

Namespace
Temporalio.Worker.Tuning
Assembly
Temporalio.dll

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

public abstract class CustomSlotSupplier : SlotSupplier
Inheritance
CustomSlotSupplier
Inherited Members

Remarks

WARNING: Custom slot suppliers are currently experimental.

Methods

MarkSlotUsed(SlotMarkUsedContext)

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.

public abstract void MarkSlotUsed(SlotMarkUsedContext ctx)

Parameters

ctx SlotMarkUsedContext

The context for marking a slot as used.

Remarks

This method will be called concurrently from multiple threads, so it must be thread-safe.

ReleaseSlot(SlotReleaseContext)

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.

public abstract void ReleaseSlot(SlotReleaseContext ctx)

Parameters

ctx SlotReleaseContext

The context for releasing a slot.

Remarks

This method will be called concurrently from multiple threads, so it must be thread-safe.

ReserveSlotAsync(SlotReserveContext, CancellationToken)

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 OperationCanceledException, as invocations of this method may be cancelled. Any other exceptions thrown will be logged and ignored. If an exception is thrown, this method will be called again after a one second wait, since it must block until a permit is returned.

public abstract Task<SlotPermit> ReserveSlotAsync(SlotReserveContext ctx, CancellationToken cancellationToken)

Parameters

ctx SlotReserveContext

The context for slot reservation.

cancellationToken CancellationToken

A cancellation token that the SDK may use to cancel the operation.

Returns

Task<SlotPermit>

A permit to use the slot which may be populated with your own data.

Remarks

This method will be called concurrently from multiple threads, so it must be thread-safe.

Exceptions

OperationCanceledException

Cancellation requested.

TryReserveSlot(SlotReserveContext)

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.

public abstract SlotPermit? TryReserveSlot(SlotReserveContext ctx)

Parameters

ctx SlotReserveContext

The context for slot reservation.

Returns

SlotPermit

Maybe a permit to use the slot which may be populated with your own data.

Remarks

This method will be called concurrently from multiple threads, so it must be thread-safe.