PM2 cron running every second

Viewed 1587

I'm using the --cron flag to run a job every hour. The issue is as soon as I deploy using pm2 deploy. I see in the logs it's running the job every second.

apps: [
    {
        name: "api",
        script: "./index.js",
        autorestart: true
    },
    {
        name: "cron",
        script: "./cron.js --cron '0 * * * *'"
    }
],

The cron syntax seems to be correct, am I missing something else?

1 Answers

The way to properly create a cronjob with pm2 is:

pm2 start index.js --no-autorestart --cron "*/15 * * * *" --name "My 15m cron job"

If passing arguments is needed then:

pm2 start index.js --no-autorestart --cron "*/15 * * * *" --name "My 15m cron job" -- --cron-15m
Related