Quantum v2.4.0 Quantum.Job View Source

This Struct defines a Job.

Usage

The struct should never be defined by hand. Use Acme.Scheduler.new_job/0 to create a new job and use the setters mentioned below to mutate the job.

This is to ensure type safety.

Link to this section Summary

Functions

Takes some config from a scheduler and returns a new job

Sets a job's name.

Sets a job's overlap.

Sets a job's run strategy.

Sets a job's schedule.

Sets a job's state.

Sets a job's task.

Sets a job's timezone.

Link to this section Types

Link to this type

state()

View Source
state() :: :active | :inactive
Link to this type

t()

View Source
t() :: %Quantum.Job{
  name: name(),
  overlap: boolean(),
  run_strategy: Quantum.RunStrategy.NodeList,
  schedule: schedule() | nil,
  state: state(),
  task: task() | nil,
  timezone: timezone()
}
Link to this type

task()

View Source
task() :: {atom(), atom(), [any()]} | (() -> any())
Link to this type

timezone()

View Source
timezone() :: :utc | String.t()

Link to this section Functions

Link to this function

new(config)

View Source
new(config :: Keyword.t()) :: t()

Takes some config from a scheduler and returns a new job

Examples

iex> Acme.Scheduler.config
...> |> Quantum.Job.new
%Quantum.Job{...}
Link to this function

set_name(job, name)

View Source
set_name(t(), atom()) :: t()

Sets a job's name.

Parameters

  1. job - The job struct to modify
  2. name - The name to set

Examples

iex> Acme.Scheduler.new_job()
...> |> Quantum.Job.set_name(:name)
...> |> Map.get(:name)
:name
Link to this function

set_overlap(job, overlap?)

View Source
set_overlap(t(), boolean()) :: t()

Sets a job's overlap.

Parameters

  1. job - The job struct to modify
  2. overlap - Enable / Disable Overlap

Examples

iex> Acme.Scheduler.new_job()
...> |> Quantum.Job.set_overlap(false)
...> |> Map.get(:overlap)
false
Link to this function

set_run_strategy(job, run_strategy)

View Source
set_run_strategy(t(), Quantum.RunStrategy.NodeList) :: t()

Sets a job's run strategy.

Parameters

  1. job - The job struct to modify
  2. run_strategy - The run strategy to set

Examples

iex> Acme.Scheduler.new_job()
...> |> Quantum.Job.run_strategy(%Quantum.RunStrategy.All{nodes: [:one, :two]})
...> |> Map.get(:run_strategy)
[:one, :two]
Link to this function

set_schedule(job, schedule)

View Source
set_schedule(t(), Crontab.CronExpression.t()) :: t()

Sets a job's schedule.

Parameters

  1. job - The job struct to modify
  2. schedule - The schedule to set. May only be of type %Crontab.CronExpression{}

Examples

iex> Acme.Scheduler.new_job()
...> |> Quantum.Job.set_schedule(Crontab.CronExpression.Parser.parse!("*/7"))
...> |> Map.get(:schedule)
Crontab.CronExpression.Parser.parse!("*/7")
Link to this function

set_state(job, atom)

View Source
set_state(t(), state()) :: t()

Sets a job's state.

Parameters

  1. job - The job struct to modify
  2. state - The state to set

Examples

iex> Acme.Scheduler.new_job()
...> |> Quantum.Job.set_state(:active)
...> |> Map.get(:state)
:active
Link to this function

set_task(job, task)

View Source
set_task(t(), task()) :: t()

Sets a job's task.

Parameters

  1. job - The job struct to modify
  2. task - The function to be performed, ex: {Heartbeat, :send, []} or fn -> :something end

Examples

iex> Acme.Scheduler.new_job()
...> |> Quantum.Job.set_task({Backup, :backup, []})
...> |> Map.get(:task)
{Backup, :backup, []}
Link to this function

set_timezone(job, timezone)

View Source
set_timezone(t(), String.t() | :utc) :: t()

Sets a job's timezone.

Parameters

  1. job - The job struct to modify
  2. timezone - The timezone to set.

Examples

iex> Acme.Scheduler.new_job()
...> |> Quantum.Job.set_timezone("Europe/Zurich")
...> |> Map.get(:timezone)
"Europe/Zurich"