Skip to content

Commit

Permalink
PLT-244 Fix Tripod Resque event listeners (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrliptontea authored Jan 17, 2024
1 parent 428acd7 commit 9d4f000
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/mongo/base/JobBase.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9d4f000

Please sign in to comment.