Pm2: Cron on offline processes

Created on 1 Nov 2016  路  6Comments  路  Source: Unitech/pm2

Currently the cron_restart option only works for online processes ([[1](https://github.com/Unitech/pm2/blob/master/lib/ProcessContainer.js#L92)][[2](https://github.com/Unitech/pm2/blob/master/lib/ProcessContainerFork.js#L19])])

That logic should be moved to the Worker so It can restart offline applications (useful when used with autorestart to false)

Low Enhancement

Most helpful comment

Also looking for this feature. Has there been any movement on it?

All 6 comments

+1

Also looking for this feature. Has there been any movement on it?

Any news on this feature ?

Any news?

Does this also cause memory to not be released? I have a node program which is being run every hour using pm2 cron, and it completes after about 20 seconds. However for the rest of the hour, pm2 list shows it as taking up ~50mb of memory.

My workaround while this isn't fixed:

  1. Create a bin/job that will execute your script for example:
#!/usr/bin/env node
const { exec } = require('child_process')

exec(process.argv.slice(2).join(' '), function (error, stderr, stdout) {
  if (error) {
    console.error(`exec error: ${error}`);
    return;
  }

  console.log(`stdout: ${stdout}`);
  console.log(`stderr: ${stderr}`);
})

// fake long running process
setInterval(() => {}, 1e6)
  1. Then this is the process declaration:
{
    "name": "cron_compute_midnight",
    "script": "./bin/job",
    "exec_mode": "fork",
    "args": "curl -s http://localhost/api/batch/compute",
    "cron_restart": "0 0 * * *"
  }

Obviously, if this issue were to be fixed the following would work:

{
    "name": "cron_compute_midnight",
    "script": "curl",
    "exec_mode": "fork",
    "args": "-s http://localhost/api/batch/compute",
    "cron_restart": "0 0 * * *",
    "autorestart": false
  }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

phra picture phra  路  3Comments

rajendar38 picture rajendar38  路  3Comments

FujiHaruka picture FujiHaruka  路  3Comments

waygee picture waygee  路  4Comments

liujb picture liujb  路  3Comments