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β
- Open Add Cron Job.
- Enter a name, a cron string and the command to run. Common cron presets:
@hourly,@daily,@weekly,@monthly,@yearly. - 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_cronjobs are removed from Sidekiq when Sidekiq stops; enabled jobs are re-queued automatically when it starts. - Newly created jobs are disabled by default.