Unitech / Unitech/pm2

Cron option not functioning properly

Open
#5,324 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

What's going wrong?

Cron option not functioning properly.

How could we reproduce this issue?

// cron.js 
console.log('cron: ' + new Date().toString());

Start cron:

pm2 start cron.js --cron '*/5 * * * * *'
pm2 logs cron

Should print every 5 seconds, but printing every 3 seconds

Supporting information

I tried with croner, all is well

const Cron = require("croner");
Cron("*/5 * * * * *", () => { console.log('cron: ' + new Date().toString());});

This print every 5 seconds.

$ pm2 report
--- PM2 report ----------------------------------------------------------------
Date                 : Thu Mar 10 2022 18:51:26 GMT+0530 (India Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.2.0
node version         : 14.17.0
node path            : /home/gaganb/.nvm/versions/node/v14.17.0/bin/pm2
argv                 : /home/gaganb/.nvm/versions/node/v14.17.0/bin/node,/home/gaganb/.nvm/versions/node/v14.17.0/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : gaganb
uid                  : 1000
gid                  : 1000
uptime               : 51min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.2.0
node version         : 14.17.0
node path            : /home/gaganb/.nvm/versions/node/v14.17.0/bin/pm2
argv                 : /home/gaganb/.nvm/versions/node/v14.17.0/bin/node,/home/gaganb/.nvm/versions/node/v14.17.0/bin/pm2,report
argv0                : node
user                 : gaganb
uid                  : 1000
gid                  : 1000
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Core(TM) i3-7020U CPU @ 2.30GHz
cpus nb              : 4
freemem              : 231378944
totalmem             : 3849801728
home                 : /home/gaganb
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬─────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name    │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼─────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ cron    │ default     │ 1.0.0   │ fork    │ 11953    │ 1s     │ 2    │ online    │ 0%       │ 41.4mb   │ gaganb   │ disabled │
└─────┴─────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list is not synchronized with saved list. Type 'pm2 save' to synchronize.
===============================================================================
--- Daemon logs --------------------------------------------
/home/gaganb/.pm2/pm2.log last 20 lines:
PM2        | 2022-03-10T18:40:13: PM2 log: App [cron:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-03-10T18:40:13: PM2 log: App [cron:0] starting in -fork mode-
PM2        | 2022-03-10T18:40:13: PM2 log: App [cron:0] online
PM2        | 2022-03-10T18:40:15: PM2 log: [PM2] Deregistering a cron job on: 0
PM2        | 2022-03-10T18:40:15: PM2 log: Stopping app:cron id:0
PM2        | 2022-03-10T18:40:15: PM2 log: App [cron:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-03-10T18:40:15: PM2 log: pid=10865 msg=process killed
PM2        | 2022-03-10T18:51:21: PM2 log: [PM2][WORKER] Registering a cron job on: 0
PM2        | 2022-03-10T18:51:21: PM2 log: App [cron:0] starting in -fork mode-
PM2        | 2022-03-10T18:51:21: PM2 log: App [cron:0] online
PM2        | 2022-03-10T18:51:24: PM2 log: App [cron:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-03-10T18:51:24: PM2 log: App [cron:0] starting in -fork mode-
PM2        | 2022-03-10T18:51:24: PM2 log: App [cron:0] online
PM2        | 2022-03-10T18:51:25: PM2 log: [PM2] Deregistering a cron job on: 0
PM2        | 2022-03-10T18:51:25: PM2 log: Stopping app:cron id:0
PM2        | 2022-03-10T18:51:25: PM2 log: App [cron:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-03-10T18:51:25: PM2 log: pid=11941 msg=process killed
PM2        | 2022-03-10T18:51:25: PM2 log: [PM2][WORKER] Registering a cron job on: 0
PM2        | 2022-03-10T18:51:25: PM2 log: App [cron:0] starting in -fork mode-
PM2        | 2022-03-10T18:51:25: PM2 log: App [cron:0] online

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the issue's pm2 start cron.js --cron and pm2 logs cron commands, then compare their timing with the croner example and the PM2 report. Use the cron.js reproduction and daemon logs to trace the unexpected restarts and verify that the cron option executes every five seconds without the three-second behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.