From: Tim Düsterhus Date: Wed, 15 May 2019 17:12:26 +0000 (+0200) Subject: Add on(Final)?Failure callbacks to AbstractBackgroundJob X-Git-Tag: 5.2.0_Alpha_1~48^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=7667b545cbdf2a40627e1b8e9b0d1f1881158033;p=GitHub%2FWoltLab%2FWCF.git Add on(Final)?Failure callbacks to AbstractBackgroundJob --- diff --git a/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php b/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php index bddbfd354f..5d26a83764 100644 --- a/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php +++ b/wcfsetup/install/files/lib/system/background/BackgroundQueueHandler.class.php @@ -104,7 +104,6 @@ class BackgroundQueueHandler extends SingletonFactory { throw $e; } - // gotta catch 'em all $job->fail(); if ($job->getFailures() <= $job::MAX_FAILURES) { @@ -115,6 +114,8 @@ class BackgroundQueueHandler extends SingletonFactory { } } else { + $job->onFinalFailure(); + // job failed too often: log \wcf\functions\exception\logThrowable($e); } diff --git a/wcfsetup/install/files/lib/system/background/job/AbstractBackgroundJob.class.php b/wcfsetup/install/files/lib/system/background/job/AbstractBackgroundJob.class.php index d8c3f12dc0..b48116bd1f 100644 --- a/wcfsetup/install/files/lib/system/background/job/AbstractBackgroundJob.class.php +++ b/wcfsetup/install/files/lib/system/background/job/AbstractBackgroundJob.class.php @@ -40,6 +40,8 @@ abstract class AbstractBackgroundJob { */ public final function fail() { $this->failures++; + + $this->onFailure(); } /** @@ -57,4 +59,31 @@ abstract class AbstractBackgroundJob { * cronjob comes along). */ abstract public function perform(); + + /** + * Called when the job failed. + * + * Note: This method MUST NOT throw any exceptions. Doing so will lead to this job immediately + * being failed completely. + * + * @see AbstractBackgroundJob::fail() + */ + public function onFailure() { + // empty + } + + /** + * Called when the job failed too often. This method can be used to perform additional + * logging for highly important jobs (e.g. into a dedicated failed_jobs table). + * + * Note: This method MUST NOT throw any exceptions. Doing so will lead to this job immediately + * being failed completely. + * + * Note: Both onFailure() and onFinalFailure() will be called on the final failure. + * + * @see AbstractBackgroundJob::onFailure() + */ + public function onFinalFailure() { + // empty + } }