@temporalio/worker
Version:
Temporal.io SDK Worker sub-package
89 lines (88 loc) • 3.24 kB
TypeScript
import { ActivitySlotInfo, CustomSlotSupplier, FixedSizeSlotSupplier, LocalActivitySlotInfo, ResourceBasedTunerOptions, SlotInfo, WorkerTuner as NativeWorkerTuner, WorkflowSlotInfo } from '@temporalio/core-bridge';
import { Duration } from '@temporalio/common/lib/time';
import { Logger } from '@temporalio/common';
export { FixedSizeSlotSupplier, ResourceBasedTunerOptions };
/**
* Controls how slots for different task types will be handed out.
*
* @experimental
*/
export type WorkerTuner = ResourceBasedTuner | TunerHolder;
/**
* This tuner allows for different slot suppliers for different slot types.
*
* @experimental
*/
export interface TunerHolder {
workflowTaskSlotSupplier: SlotSupplier<WorkflowSlotInfo>;
activityTaskSlotSupplier: SlotSupplier<ActivitySlotInfo>;
localActivityTaskSlotSupplier: SlotSupplier<LocalActivitySlotInfo>;
}
/**
* Controls how slots are handed out for a specific task type.
*
* For now, only {@link ResourceBasedSlotOptions} and {@link FixedSizeSlotSupplier} are supported,
* but we may add support for custom tuners in the future.
*
* @experimental
*/
export type SlotSupplier<SI extends SlotInfo> = ResourceBasedSlotsForType | FixedSizeSlotSupplier | CustomSlotSupplier<SI>;
/**
* Resource based slot supplier options for a specific kind of slot.
*
* @experimental
*/
type ResourceBasedSlotsForType = ResourceBasedSlotOptions & {
type: 'resource-based';
tunerOptions: ResourceBasedTunerOptions;
};
/**
* Options for a specific slot type within a {@link ResourceBasedSlotsForType}
*
* @experimental
*/
export interface ResourceBasedSlotOptions {
/**
* Amount of slots that will be issued regardless of any other checks.
* Defaults to 2 for workflow tasks and 1 for activity tasks.
*/
minimumSlots?: number;
/**
* Maximum amount of slots permitted
* Defaults to 1000 for workflow tasks and 2000 for activity tasks.
*/
maximumSlots?: number;
/**
* Minimum time we will wait (after passing the minimum slots number) between handing out new
* slots. Defaults to 10ms for workflow tasks and 50ms for activity tasks.
*/
rampThrottle?: Duration;
}
/**
* This tuner attempts to maintain certain levels of resource usage when under load. You do not
* need more than one instance of this when using it for multiple slot types.
*
* @experimental
*/
export interface ResourceBasedTuner {
/**
* Options for the tuner
*/
tunerOptions: ResourceBasedTunerOptions;
/**
* Options for workflow task slots. Defaults to a minimum of 2 slots and a maximum of 1000 slots
* with no ramp throttle
*/
workflowTaskSlotOptions?: ResourceBasedSlotOptions;
/**
* Options for activity task slots. Defaults to a minimum of 1 slots and a maximum of 2000 slots
* with 50ms ramp throttle
*/
activityTaskSlotOptions?: ResourceBasedSlotOptions;
/**
* Options for local activity task slots. Defaults to a minimum of 1 slots and a maximum of 2000
* slots with 50ms ramp throttle
*/
localActivityTaskSlotOptions?: ResourceBasedSlotOptions;
}
export declare function asNativeTuner(tuner: WorkerTuner, logger: Logger): NativeWorkerTuner;