Skip to content

Commit

Permalink
Fix failed jobs when produces for a listener closure (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
joskfg authored Jan 25, 2022
1 parent 350564f commit e34aa7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Queue/Jobs/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public function failed($e): void
{
$this->markAsFailed();

if (method_exists($listener = $this->resolve($this->listenerClass), 'failed')) {
if (
$this->listenerClass !== \Closure::class
&& method_exists($listener = $this->resolve($this->listenerClass), 'failed')
) {
$listener->failed($this->payload(), $e);
}
}
Expand Down Expand Up @@ -113,7 +116,7 @@ public function displayName(): string
{
return $this->getName();
}

/**
* Get the timestamp indicating when the job should timeout.
*/
Expand Down
19 changes: 19 additions & 0 deletions tests/Queue/Jobs/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ public function testFailing()
self::assertEquals($message->getBody(), $listener->payload);
}

public function testFailingClosure()
{
$exception = new \Exception("Exception in `fire` method");

$app = new Container();
$message = $this->getMessage();

$queueManager = m::spy(Manager::class);

$job = new Job($app, $queueManager, $message,
'trim',
\Closure::class
);

$job->failed($exception);

self::assertTrue($job->hasFailed());
}

public function testGetJobId()
{
$job = $this->getJob();
Expand Down

0 comments on commit e34aa7e

Please sign in to comment.