Skip to main content

Cron Jobs

CmCronJob lets admins create, enable, disable, run and inspect scheduled shell commands from cm-admin. Jobs run on Sidekiq through sidekiq-cron, and every run is logged in CmCronJobLog.

Quick example​

rails g cm_admin:add_scheduler
rails db:migrate

Add CmCronJob and CmCronJobLog to config.included_models, start Sidekiq, then create a job with a name, a cron string (@daily, 0 2 * * *) and a command, and click Enable.

Setup​

1. Run the scheduler generator​

rails g cm_admin:add_scheduler

2. Register the models​

Make sure CmCronJob and CmCronJobLog are in config.included_models.

3. Migrate and start Sidekiq​

rails db:migrate
bundle exec sidekiq

Using cron jobs​

  • Filters β€” by name, status, last run time and last run status.
  • Sortable columns β€” name, updated time, created time.
  • Actions β€” enable, disable, run now and delete, from CmAdmin::CmCronJob.
  • Logs β€” each job's Logs tab lists every run with start/end times, status and output.

Recipes​

Add a cron job​

  1. Open Add Cron Job.
  2. Enter a name, a cron string and the command to run. Common cron presets: @hourly, @daily, @weekly, @monthly, @yearly.
  3. Save, then click Enable β€” new jobs are disabled by default.

Edit a cron job​

Open the job's Edit page, change the fields and save.

View job logs​

Open the job's Logs tab for start/end times, status and a link to the output.

Notes​

  • All cm_cron jobs are removed from Sidekiq when Sidekiq stops; enabled jobs are re-queued automatically when it starts.
  • Newly created jobs are disabled by default.