Fix add a protection to be able to process jobs not closed correctly.

This commit is contained in:
Laurent Destailleur 2024-06-11 18:01:42 +02:00
parent 94a8b85d8d
commit 335c5761f9

View File

@ -167,7 +167,7 @@ if (isset($argv[4]) && $argv[4] == '--force') {
$forcequalified = 1;
}
// create a jobs object
// Create a jobs object
$object = new Cronjob($db);
$filter = array();
@ -180,6 +180,15 @@ if (!empty($id)) {
$filter['t.rowid'] = $id;
}
// Update old jobs that were not closed correctly so processing is moved from 1 to 0 (otherwise task stopped with fatal error are always in status "in progress")
$sql = "UPDATE ".MAIN_DB_PREFIX."cronjob set processing = 0";
$sql .= " WHERE processing = 1";
$sql .= " AND datelastrun <= '".$db->idate(dol_now() - 24*3600, 'gmt')."'";
$sql .= " AND datelastresult IS NULL";
$db->query($sql);
$result = $object->fetchAll('ASC,ASC,ASC', 't.priority,t.entity,t.rowid', 0, 0, 1, $filter, 0);
if ($result < 0) {
echo "Error: ".$object->error;