From 9d4f0007c54bbfecdb4d755a1fc1ab6923918212 Mon Sep 17 00:00:00 2001 From: Grzegorz Rajchman Date: Wed, 17 Jan 2024 09:52:08 +0000 Subject: [PATCH] PLT-244 Fix Tripod Resque event listeners (#146) --- src/mongo/base/JobBase.class.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/mongo/base/JobBase.class.php b/src/mongo/base/JobBase.class.php index c08ad8f7..93d052fc 100644 --- a/src/mongo/base/JobBase.class.php +++ b/src/mongo/base/JobBase.class.php @@ -31,8 +31,8 @@ abstract class JobBase extends \Tripod\Mongo\DriverBase public function __construct() { - \Resque_Event::listen('beforePerform', [$this, 'beforePerform']); - \Resque_Event::listen('onFailure', [$this, 'onFailure']); + \Resque_Event::listen('beforePerform', [self::class, 'beforePerform']); + \Resque_Event::listen('onFailure', [self::class, 'onFailure']); } /** @@ -63,7 +63,12 @@ abstract protected function getStatFailureIncrementKey(); */ public static function beforePerform(\Resque_Job $job) { - $job->getInstance()->validateArgs(); + $instance = $job->getInstance(); + if (!$instance instanceof self) { + return; + } + + $instance->validateArgs(); } public function setUp() @@ -96,14 +101,17 @@ public function tearDown() /** * Resque event when a job failures * - * @param \Exception $e Exception - * @param \Resque_Job $job The failed job + * @param \Throwable|\Exception $e Exception or Error + * @param \Resque_Job $job The failed job * @return void */ - public static function onFailure(\Exception $e, \Resque_Job $job) + public static function onFailure($e, \Resque_Job $job) { - /** @var JobBase $failedJob */ $failedJob = $job->getInstance(); + if (!$failedJob instanceof self) { + return; + } + $failedJob->errorLog('Caught exception in '. get_called_class() . ': ' . $e->getMessage()); $failedJob->getStat()->increment($failedJob->getStatFailureIncrementKey()); throw $e;