View Source Bonny.PeriodicTask (bonny v1.4.0)

Register periodically run tasks. Use for running tasks as a part of reconciling a CRD with a lifetime, duration, or interval field.

Note: Must be started by your operator.

Add Bonny.PeriodicTask.sttart_link(:ok) to your application.

Functions are expected to return one of:

  • :ok - task will be passed to subsequent calls
  • {:ok, new_state} state field will be updated in task and provided to next call
  • {:stop, reason} task will be removed from execution loop. Use for tasks opting out of being re-run
  • any() - any other result is treated as an error, and the execution loop will be halted

Examples

Registering a task

iex> Bonny.PeriodicTask.new(:pod_evictor, {PodEvictor, :evict, [reconcile_payload_map]}, 5000)

Unregistering a task

iex> Bonny.PeriodicTask.unregister(:pod_evictor)

Summary

Functions

Returns a specification to start this module under a supervisor.

Registers and starts a new task given Bonny.PeriodicTask attributes

Registers and starts a new Bonny.PeriodicTask

Unregisters and stops a Bonny.PeriodicTask

Types

@type t() :: %Bonny.PeriodicTask{
  handler: (... -> any()) | mfa(),
  id: binary() | atom(),
  interval: pos_integer(),
  jitter: float(),
  state: any()
}

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

new(id, handler, interval \\ 5000)

View Source
@spec new(binary() | atom(), mfa() | (... -> any()), pos_integer()) ::
  {:ok, pid()} | {:error, term()}

Registers and starts a new task given Bonny.PeriodicTask attributes

@spec register(t()) :: {:ok, pid()} | {:error, term()}

Registers and starts a new Bonny.PeriodicTask

@spec start_link(any()) :: :ignore | {:error, any()} | {:ok, pid()}
@spec unregister(t() | atom()) :: any()

Unregisters and stops a Bonny.PeriodicTask