Commit ae76bab0 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Try to remove lock when exception thrown in cron function (bug #685640)



If a cron function causes an exception for whatever reason, then the
cron will stop, but the lock isn't removed. The job then isn't tried
again for another 24 hours.

Instead we should try to set the next run time and remove the lock.
Cron functions that run frequently, but fail due to some temporary
problem, will not be forced to stop for 24 hours.  On the other hand,
very frequent cron functions that throw exceptions on every run will
be spammy.

Obviously, this change has no effect on cron functions that fail due
to script timeouts, out-of-memory errors, or which exit for any other
reason.

Change-Id: I3bfe08c2ebba62cbd82045e66438a6442d1f1fe8
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent d23200b1
......@@ -91,10 +91,16 @@ foreach (plugin_types() as $plugintype) {
log_info("Running $classname::" . $job->callfunction);
safe_require($plugintype, $job->plugin, 'lib.php', 'require_once');
call_static_method(
$classname,
$job->callfunction
);
try {
call_static_method($classname, $job->callfunction);
}
catch (Exception $e) {
log_message($e->getMessage(), LOG_LEVEL_WARN, true, true, $e->getFile(), $e->getLine(), $e->getTrace());
$output = $e instanceof MaharaException ? $e->render_exception() : $e->getMessage();
echo "$output\n";
// Don't call handle_exception; try to update next run time and free the lock
}
$nextrun = cron_next_run_time($start, (array)$job);
......@@ -147,7 +153,16 @@ if ($jobs) {
log_info("Running core cron " . $job->callfunction);
$function = $job->callfunction;
$function();
try {
$function();
}
catch (Exception $e) {
log_message($e->getMessage(), LOG_LEVEL_WARN, true, true, $e->getFile(), $e->getLine(), $e->getTrace());
$output = $e instanceof MaharaException ? $e->render_exception() : $e->getMessage();
echo "$output\n";
// Don't call handle_exception; try to update next run time and free the lock
}
$nextrun = cron_next_run_time($start, (array)$job);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment