Exq Scheduler 
Exq Scheduler is a cron like job scheduler for Exq, it's also compatible with Sidekiq and Resque.
Installation
defp deps do
[{:exq_scheduler, "~> x.x.x"}]
end
Overview
Exq Scheduler pushes jobs into the queue at intervals specified by the schedule configuration. It is designed to run on more than one machine for redundancy without causing duplicate jobs to be scheduled.
Configuration
By default Exq Scheduler will read the configuration from application environment.
Storage
Exq Scheduler uses redis to store internal state of the scheduler.
It uses "#{exq_namespace}:sidekiq-scheduler" for storing scheduler internal metadata.
config :exq_scheduler, :storage,
exq_namespace: "exq" # exq redis namespace
Redis Client
Exq Scheduler will start a Redis Client under it's supervisor tree. It
supports both Redix and
RedixSentinel. Redix
is used by default. The name used in the
child_spec
and config should be the same.
config :exq_scheduler, :redis,
name: ExqScheduler.Redis.Client,
child_spec: {Redix, ["redis://localhost:6379", name: ExqScheduler.Redis.Client]}
Schedules
config :exq_scheduler, :schedules,
signup_report: %{
description: "Send the list of newly signed up users to admin",
cron: "0 * * * *",
class: "SignUpReportWorker",
include_metadata: true,
args: [],
queue: "default"
},
login_report: %{
cron: "0 * * * *",
class: "LoginReportWorker"
}
cron: required Refer cron documentation for syntax. Time zone of a single schedule can be changed by specifying the time zone at the end. Example0 * * * * Asia/Kolkata.class: required Name of the worker class.queue: Name of the worker queue. Defaults to"default".args: List of values that should be passed toperformmethod in worker. Defaults to[].enabled: Schedule is disabled if set to nil or false. Defaults totrue.include_metadata: If set to non nil/false, the schedule time in unix time format (example{"scheduled_at"=>1527750039.080837}) will be passed as an extra argument toperformmethod in worker. Defaults tonil.description: a text that will be shown in sidekiq web
Misc
Scheduling each and every job at the exact time might not be possible
every time. The node might get restarted, the process might get
descheduled by the OS etc. To solve this exq scheduler by default
schedules any missed jobs in the last 1 hour. This interval can be
configured by changing missed_jobs_window value.
config :exq_scheduler,
missed_jobs_window: 60 * 60 * 1000,
time_zone: "Asia/Kolkata"
missed_jobs_window: Missed jobs interval in milliseconds. Defaults to60 * 60 * 1000time_zone: Default time zone for all schedules. Defaults to system time zone.
Web
Exq Scheduler is compatible with
sidekiq-scheduler
web UI. Make sure the exq_namespace value and the namespace in
sidekiq are same.
Example
Sample Mix project along with sidekiq web UI is created
inside demo directory to demonstrate the configuration.
Sidekiq web interface requires Ruby to be installed.
To install dependencies
> cd demo
> mix deps.get
> cd sidekiq-ui
> bundle install
To start it
> cd demo
> ./start_demo.sh