CRON Jobs
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
I noticed the following issue (most likely it’s supposed to work this way), and maybe you could correct me if I’m wrong. I want to use PM2’s cron feature because it greatly simplifies the logic and management of my application pool. However, I noticed that when I specify the cron parameter, after running pm2 start ./configs/ecosystem.config.cjs, all my cron jobs execute immediately instead of waiting for the scheduled time. After that, everything works correctly.
Is there a way to specify a flag to prevent this immediate execution, or is this a bug?
const common = {
cwd: path.resolve(__dirname, '..'),
exec_mode: 'fork',
interpreter: 'node',
autorestart: true,
watch: ['src/node'],
// Logs
merge_logs: true,
log_type: 'json',
log_date_format: 'DD-MM-YYYY HH:mm',
}
{
...common,
name: 'SharePoint:JOB',
script: './src/node/services/SharePoint.js',
log_file: `./logs/SharePoint.log`,
autorestart: false,
cron: '0 0 * * *',
env: { MODE: 'JOB' },
},
Here, the job is scheduled to run at 00:00, but when the script starts, it executes immediately and only then runs according to the schedule. How can I change the behavior so that the process is in a stopped state when it starts?
Please don’t give me recommendations to use cron with Linux or node-cron. I am aware of these solutions, but I need a solution at the process level. Maybe, if regular cron isn’t implemented in PM2, it would be worth implementing it? I think this functionality is needed by many people, and considering that PM2 is a process manager, it should definitely be able to run processes according to a schedule.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior with pm2 start ./configs/ecosystem.config.cjs and the cron setting shown in the issue. Start by tracing PM2's cron process-start handling; done means a cron-configured process remains stopped after startup and first runs only at its scheduled time, while continuing its normal schedule afterward.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- devops
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100