Skip to content

Commit 08ba875

Browse files
author
Marius Burkard
committed
Merge branch '5823-repair-stale-cronjobs' into 'develop'
remove stale "running" cronjobs Closes #5823 See merge request ispconfig/ispconfig3!1289
2 parents 5b168ca + 8dc4ce1 commit 08ba875

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

server/lib/classes/cronjob.inc.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ protected function onPrepare() {
9999
if($conf['log_priority'] <= LOGLEVEL_DEBUG) print "Called onPrepare() for class " . get_class($this) . "\n";
100100
// check the run time and values for this job
101101

102+
// remove stale cronjobs
103+
$data = $app->db->queryAllRecords("SELECT `last_run` FROM `sys_cron` WHERE `name` = ? AND (`last_run` IS NOT NULL AND `last_run` < DATE_SUB(NOW(), INTERVAL 24 HOUR)) AND `running` = 1", get_class($this));
104+
foreach ($data as $rec) {
105+
if($conf['log_priority'] <= LOGLEVEL_WARN) print "Removing stale sys_cron entry for ".get_class($this)." (last run ".$rec['last_run'].")\n";
106+
$app->db->query("DELETE FROM `sys_cron` WHERE `name` = ? AND `last_run` = ? AND `running` = 1", $rec['name'], $rec['last_run']);
107+
}
108+
102109
// get previous run data
103110
$data = $app->db->queryOneRecord("SELECT `last_run`, `next_run`, IF(`last_run` IS NOT NULL AND `last_run` < DATE_SUB(NOW(), INTERVAL 24 HOUR), 0, `running`) as `running` FROM `sys_cron` WHERE `name` = ?", get_class($this));
104111
if($data) {

0 commit comments

Comments
 (0)