๐ Cron Job Setup Documentation
๐ Overviewโ
The CM Cron Job feature allows you to manage scheduled tasks directly within the cm-admin interface.
You can create, edit, enable, disable, execute, and view logs for each cron job from a user-friendly dashboard.
โจ Featuresโ
-
๐ Filters: Search cron jobs by:
- Name
- Status
- Last run time
- Last run status
-
๐ Sortable Columns:
- Name
- Updated time
- Created time
-
โ๏ธ Custom Actions:
- โ Enable or โ Disable a cron job
- โถ๏ธ Manually execute a cron job
-
๐ Detailed Views:
- Job information: name, cron string, command, status, last run time, output
- Access logs for each run
๐ ๏ธ Setup Instructionsโ
1. ๐ฆ Run the CMAdmin Scheduler Generatorโ
Generate the necessary files:
rails g cm_admin:add_scheduler
2. ๐งฑ Ensure Required Models Existโ
Your application must include the following models:
CmCronJobCmCronJobLog
3. ๐ Integrate Sidekiqโ
-
Run database migrations:
rails db:migrate -
Start Sidekiq to enable background processing.
๐ก Note:
- All
cm_cronjobs are removed from Sidekiq when Sidekiq is shut down.- When Sidekiq is started, all enabled cron jobs will be automatically re-added to the queue.
4. ๐งฉ Use Custom Actionsโ
Available via the CmAdmin::CmCronJob concern:
- ๐ซ Disable Job โ Deactivates an active job.
- ๐ข Enable Job โ Activates a disabled job.
- ๐ Execute Job โ Runs a job immediately.
- ๐๏ธ Delete Job โ Removes the job permanently.
โ ๏ธ Note: Newly created jobs are disabled by default. Use the Enable button to activate them.
5. ๐ View Cron Job Logsโ
Each jobโs Logs tab includes:
- ๐ Start and completion timestamps
- ๐ Execution status
- ๐ Links to detailed log output
๐งช Example Usageโ
โ Add a New Cron Jobโ
-
Navigate to the Add Cron Job page.
-
Provide the following details:
-
๐ท๏ธ Name: A unique identifier for the job.
-
๐ฐ๏ธ Cron String: Set the schedule using a valid cron expression. Common presets:
@hourlyโ Every hour@dailyโ Every day@weeklyโ Every week@monthlyโ Every month@yearlyโ Every year
-
๐ป Command: The shell command to be executed.
-
-
Click Save โ to create the job.
โ๏ธ Edit an Existing Cron Jobโ
- Open the Edit Cron Job page for the desired job.
- Modify the necessary fields.
- Click Save ๐พ to update the job.
๐ View Job Logsโ
-
Visit the Logs tab on a cron jobโs detail page.
-
Review:
- โฑ๏ธ Start and end times
- ๐ Status of execution
- ๐ Link to output logs
โ Conclusionโ
The CM Cron Job feature in cm-admin empowers you to manage scheduled tasks with confidence. With detailed controls, logging, and Sidekiq support, you can automate background operations efficiently and reliably. ๐