Skip to content

CRON Jobs #6030

@O-YENA

Description

@O-YENA

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions