/schedulex

Primary LanguageElixirGNU General Public License v3.0GPL-3.0

Schedulex

This is a scheduler for elixir that runs all jobs in a given module on a defined interval.

Installation

If available in Hex, the package can be installed by adding schedulex to your list of dependencies in mix.exs:

def deps do
  [
    {:schedulex, "~> 0.1.0"}
  ]
end

Schedulex needs to be run as a worker, so in your application, you'd need to add something like this.

def start(_type, _args) do
    import Supervisor.Spec

    children = [
      worker(Schedulex, []),
    ]
    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end

Configuration

Schedulex requires two configuration keys:

config :schedulex, interval_minutes: 5, job_module: MyApp.JobsModule

Interval Minutes

This is how often the jobs module's run function will be called. Putting an interval of 5 would run the module on every 5 minute interval of an hour. Note that this does not run every 5 minutes since the scheduler has started.

Job Module

This is a module that simply needs to have a public run/0.

Further Documentation

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/schedulex.