Skip to content

Documentation / @andrew_l/app / WorkerDefinition

Interface: WorkerDefinition<P, S, M, C, RuntimeContext, EntryContext, SetupContext> ​

Worker definition — extends AppDefinition with strategy, per-task entry, and concurrency config.

Extends ​

  • AppDefinition<P, S, M, RuntimeContext, EntryContext, SetupContext>

Type Parameters ​

P ​

P extends ObjectPropsOptions = { }

S ​

S extends Record<string, any> = { }

M ​

M extends Record<string, AnyFunction> = { }

C ​

C extends WorkerStrategy = WorkerStrategy

RuntimeContext ​

RuntimeContext extends RuntimeContext = RuntimeContext<S & M>

EntryContext ​

EntryContext extends EntryContext = EntryContext<C> & S & M

SetupContext ​

SetupContext extends SetupContext = SetupContext<M>

Properties ​

description? ​

optional description: string

Describe what your application does

Inherited from ​

AppDefinition.description


disabled? ​

optional disabled: boolean

Disable worker

Default ​

ts
false

executeStrategy ​

executeStrategy: C


filePath? ​

optional filePath: null | string

Path to the file where this definition exports default Usually you should not use this option, because it tracks automatically

Inherited from ​

AppDefinition.filePath


logger? ​

optional logger: false | Logger | (definition) => Logger

Logger instance or constructor function

Inherited from ​

AppDefinition.logger


methods? ​

optional methods: M & ThisType<RuntimeContext>

Custom methods which will be available under this context

Inherited from ​

AppDefinition.methods


name ​

name: string

Name of your awesome application

Inherited from ​

AppDefinition.name


props? ​

optional props: P

Props options to be parsed from cli arguments of env variables

Inherited from ​

AppDefinition.props


taskLimit? ​

optional taskLimit: number

Maximum limit of queued tasks

Default ​

ts
50

taskParallel? ​

optional taskParallel: number

Amount of task to be executed in parallel

Default ​

ts
2

Methods ​

entry()? ​

optional entry(this, props): Awaitable<void | WorkerResult | WorkerResult[]>

Entry function that will be called each time when worker handle a job

Parameters ​

this ​

EntryContext

props ​

ExtractPropTypes<P>

Returns ​

Awaitable<void | WorkerResult | WorkerResult[]>

Overrides ​

AppDefinition.entry


setup()? ​

optional setup(this, props): Awaitable<S>

Setup function will be called once while worker setup.

Parameters ​

this ​

SetupContext

props ​

ExtractPropTypes<P>

Returns ​

Awaitable<S>

Overrides ​

AppDefinition.setup


shutdown()? ​

optional shutdown(this, props): Awaitable<void>

Shutdown function that will be called before application/process graceful shutdown

Parameters ​

this ​

RuntimeContext

props ​

ExtractPropTypes<P>

Returns ​

Awaitable<void>

Inherited from ​

AppDefinition.shutdown


stop()? ​

optional stop(this, props): Awaitable<void>

Stop function that will be called each time when application stops

Parameters ​

this ​

RuntimeContext

props ​

ExtractPropTypes<P>

Returns ​

Awaitable<void>

Inherited from ​

AppDefinition.stop