Logo Orsak

ScalingEffectJob<'r, 's, 'err> Type

A background service that runs an effect over and over in a baseline worker, and in extra workers added and removed according to GetWorkload, which is checked every monitorInterval, 10 seconds by default. At most maxExtraWorkers are added, 10 by default.

The service keeps its workers running, but leaves how each run behaves to the effect. When a run fails or throws, the error is logged, and the worker waits before running the effect again, from restartDelay, 1 second by default, doubling with each failure in a row, up to maxRestartDelay, 1 minute by default. Retrying, backing off when there is nothing to do, and logging errors in a way that suits the work, belong in the effect, composed with the functions of Orsak.Resilience.

work is called once for each worker, and its effect is run by that worker until it stops. Compose the effect inside work, so each worker gets its own state, such as the backoff of Effect.addDelay:

 fun queue -> handleNext queue |> Effect.addDelayWithMax_ 1.<s> 10.<s>
val queue: 'a
A worker stops when its token is cancelled. The token is passed to runnerFactory, and delays in the effect only end early when the environment provides it, such as through ICancellationProvider.

Constructors

Constructor Description

ScalingEffectJob(name, logger, state, work, runnerFactory, ?maxExtraWorkers, ?monitorInterval, ?restartDelay, ?maxRestartDelay)

Full Usage: ScalingEffectJob(name, logger, state, work, runnerFactory, ?maxExtraWorkers, ?monitorInterval, ?restartDelay, ?maxRestartDelay)

Parameters:
Returns: ScalingEffectJob<'r, 's, 'err>
name : string
logger : ILogger
state : 's
work : 's -> Effect<'r, unit, 'err>
runnerFactory : CancellationToken -> 'r
?maxExtraWorkers : int
?monitorInterval : TimeSpan
?restartDelay : TimeSpan
?maxRestartDelay : TimeSpan
Returns: ScalingEffectJob<'r, 's, 'err>

Instance members

Instance member Description

this.GetWorkload

Full Usage: this.GetWorkload

Parameters:
Returns: Task<WorkerLoad>
Modifiers: abstract

How much work the job has, checked every monitorInterval to decide whether to add or remove a worker. An exception is logged, and the workers stay as they are until the next check.

arg0 : CancellationToken
Returns: Task<WorkerLoad>

Type something to start searching.