bonny v0.4.1 Bonny.PeriodicTask

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)

Link to this section 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

Link to this section Types

Link to this type

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

Link to this section Functions

Link to this function

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

new(id, handler, interval \\ 5000)
new(atom(), mfa() | (... -> any()), pos_integer() | nil) ::
  {:ok, pid()} | {:error, term()}

Registers and starts a new task given Bonny.PeriodicTask attributes

Link to this function

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

Registers and starts a new Bonny.PeriodicTask

Link to this function

start_link(any)
start_link(any()) :: :ignore | {:error, any()} | {:ok, pid()}

Link to this function

unregister(id)
unregister(t() | atom()) :: any()

Unregisters and stops a Bonny.PeriodicTask