Skip to content

Commit 9d4f000

Browse files
authored
PLT-244 Fix Tripod Resque event listeners (#146)
1 parent 428acd7 commit 9d4f000

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/mongo/base/JobBase.class.php

+15-7
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ abstract class JobBase extends \Tripod\Mongo\DriverBase
3131

3232
public function __construct()
3333
{
34-
\Resque_Event::listen('beforePerform', [$this, 'beforePerform']);
35-
\Resque_Event::listen('onFailure', [$this, 'onFailure']);
34+
\Resque_Event::listen('beforePerform', [self::class, 'beforePerform']);
35+
\Resque_Event::listen('onFailure', [self::class, 'onFailure']);
3636
}
3737

3838
/**
@@ -63,7 +63,12 @@ abstract protected function getStatFailureIncrementKey();
6363
*/
6464
public static function beforePerform(\Resque_Job $job)
6565
{
66-
$job->getInstance()->validateArgs();
66+
$instance = $job->getInstance();
67+
if (!$instance instanceof self) {
68+
return;
69+
}
70+
71+
$instance->validateArgs();
6772
}
6873

6974
public function setUp()
@@ -96,14 +101,17 @@ public function tearDown()
96101
/**
97102
* Resque event when a job failures
98103
*
99-
* @param \Exception $e Exception
100-
* @param \Resque_Job $job The failed job
104+
* @param \Throwable|\Exception $e Exception or Error
105+
* @param \Resque_Job $job The failed job
101106
* @return void
102107
*/
103-
public static function onFailure(\Exception $e, \Resque_Job $job)
108+
public static function onFailure($e, \Resque_Job $job)
104109
{
105-
/** @var JobBase $failedJob */
106110
$failedJob = $job->getInstance();
111+
if (!$failedJob instanceof self) {
112+
return;
113+
}
114+
107115
$failedJob->errorLog('Caught exception in '. get_called_class() . ': ' . $e->getMessage());
108116
$failedJob->getStat()->increment($failedJob->getStatFailureIncrementKey());
109117
throw $e;

0 commit comments

Comments
 (0)