Quantum v2.3.3 Quantum.Scheduler behaviour View Source

Defines a quantum Scheduler.

When used, the quantum scheduler expects the :otp_app as option. The :otp_app should point to an OTP application that has the quantum runner configuration. For example, the quantum scheduler:

defmodule MyApp.Scheduler do
  use Quantum.Scheduler, otp_app: :my_app
end

Could be configured with:

config :my_app, MyApp.Scheduler,
  jobs: [
    {"@daily", {Backup, :backup, []},
  ]

Configuration:

  • :timeout - Sometimes, you may come across GenServer timeout errors esp. when you have too many jobs or high load. The default GenServer.call timeout is 5000.

  • :jobs - list of cron jobs to execute

  • :global - When you have a cluster of nodes, you may not want same jobs to be generated on every single node, e.g. jobs involving db changes.

    In this case, you may choose to run Quantum as a global process, thus preventing same job being run multiple times because of it being generated on multiple nodes. With the following configuration, Quantum will be run as a globally unique process across the cluster.

  • :schedule - Default schedule of new Job

  • :run_strategy - Default Run Strategy of new Job

  • :overlap - Default overlap of new Job,

  • :timezone - Default timezone of new Job

Link to this section Summary

Callbacks

Activates a job by name

Adds a new job

Returns the configuration stored in the :otp_app environment

Deactivates a job by name

Deletes all jobs

Deletes a job by name

Resolves a job by name

A callback executed when the quantum starts

Returns the list of currently defined jobs

Creates a new Job. The job can be added by calling add_job/1

Starts supervision and return {:ok, pid} or just :ok if nothing needs to be done

Shuts down the quantum represented by the given pid

Link to this section Types

Link to this section Callbacks

Link to this callback activate_job(arg0, atom) View Source
activate_job(GenStage.stage(), atom()) :: :ok

Activates a job by name

Adds a new job

Returns the configuration stored in the :otp_app environment.

Link to this callback deactivate_job(arg0, atom) View Source
deactivate_job(GenStage.stage(), atom()) :: :ok

Deactivates a job by name

Link to this callback delete_all_jobs(arg0) View Source
delete_all_jobs(GenStage.stage()) :: :ok

Deletes all jobs

Link to this callback delete_job(arg0, atom) View Source
delete_job(GenStage.stage(), atom()) :: :ok

Deletes a job by name

Link to this callback find_job(arg0, atom) View Source
find_job(GenStage.stage(), atom()) :: Quantum.Job.t() | nil

Resolves a job by name

Link to this callback init(config) View Source (optional)
init(config :: Keyword.t()) :: Keyword.t()

A callback executed when the quantum starts.

It takes the quantum configuration that is stored in the application environment, and may change it to suit the application business.

It must return the updated list of configuration

Returns the list of currently defined jobs

Creates a new Job. The job can be added by calling add_job/1.

Link to this callback start_link(opts) View Source
start_link(opts :: Keyword.t()) ::
  {:ok, pid()} | {:error, {:already_started, pid()}} | {:error, term()}

Starts supervision and return {:ok, pid} or just :ok if nothing needs to be done.

Returns {:error, {:already_started, pid}} if the repo is already started or {:error, term} in case anything else goes wrong.

Options

See the configuration in the moduledoc for options.

Link to this callback stop(server, timeout) View Source
stop(server :: GenServer.server(), timeout()) :: :ok

Shuts down the quantum represented by the given pid.