Skip to content

Commit

Permalink
Merge pull request Unitech#4492 from bvsubhash/fix-cronjob-issue
Browse files Browse the repository at this point in the history
fix: stop and delete cron immediately on deletion of a process
  • Loading branch information
Unitech authored Nov 14, 2019
2 parents 376bd91 + 474f76b commit 378d443
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/God/ActionMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ module.exports = function(God) {
God.deleteProcessId = function(id, cb) {
God.stopProcessId(id, function(err, proc) {
if (err) return cb(God.logAndGenerateError(err), {});
var proc = God.clusters_db[id];
God.deleteCron(proc);
// ! transform to slow object
delete God.clusters_db[id];

Expand Down Expand Up @@ -617,6 +619,24 @@ module.exports = function(God) {
return fn(null, {success:true});
};

/**
* Deletes the cron job on deletion of process
*/
God.deleteCron = function(proc) {
if (!proc ||
!proc.pm2_env ||
proc.pm2_env.pm_id === undefined ||
!proc.pm2_env.cron_restart ||
!God.CronJobs.has(proc.pm2_env.pm_id))
return;

console.log('[PM2] Deregistering a cron job on:', proc.pm2_env.pm_id);

var job = God.CronJobs.get(proc.pm2_env.pm_id);
job.stop();
God.CronJobs.delete(proc.pm2_env.pm_id);
};

/**
* Description
* @method reloadLogs
Expand Down

0 comments on commit 378d443

Please sign in to comment.