Repeated Task
class RepeatedTask @JvmOverloads constructor(val name: String, meterRegistry: MeterRegistry = Metrics.globalRegistry, repeatedTaskConfig: RepeatedTaskConfig = RepeatedTaskConfig(), retryPolicy: suspend RetryFailure<Throwable>.() -> RetryInstruction = defaultThrowableRetryPolicy +
binaryExponentialBackoff(
base = repeatedTaskConfig.defaultJitterMs,
max = repeatedTaskConfig.defaultMaxDelayMs
), taskConfig: TaskConfig = TaskConfig(), task: (name: String, taskConfig: TaskConfig) -> Status)
A RepeatedTask runs a repeated task at the user controlled rate.
Tasks are called with a TaskConfig and are expected to return a Status or throw an exception. By default, the retry policy will try again if an exception is thrown and will apply a binaryExponentialBackoff using the supplied RepeatedTaskConfig. A Status.NO_WORK or Status.FAILED will be mapped to NoWorkForTaskException and FailedTaskException and thrown to apply the retry policy.
If the Status.NO_RESCHEDULE is returned, the RepeatedTask is shutdown.
Example usage:
val repeatedTask = RepeatedTask("task") {
// do task stuff...
return Status.OK
}
repeatedTask.startUp()Content copied to clipboard
Constructors
Link copied to clipboard
constructor(name: String, meterRegistry: MeterRegistry = Metrics.globalRegistry, repeatedTaskConfig: RepeatedTaskConfig = RepeatedTaskConfig(), retryPolicy: suspend RetryFailure<Throwable>.() -> RetryInstruction = defaultThrowableRetryPolicy +
binaryExponentialBackoff(
base = repeatedTaskConfig.defaultJitterMs,
max = repeatedTaskConfig.defaultMaxDelayMs
), taskConfig: TaskConfig = TaskConfig(), task: (name: String, taskConfig: TaskConfig) -> Status)