Skip to content

Commit

Permalink
StompJob (#36)
Browse files Browse the repository at this point in the history
* Update StompJob.php

ACK in StompJob

* Apply fixes from StyleCI

* Update StompJob.php

in case of duplicate job ID insert fails

* Apply fixes from StyleCI

* Update StompJob.php

add to method

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
ngaspari and StyleCIBot authored May 17, 2024
1 parent 14c0e73 commit 7385a3e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Queue/Jobs/StompJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Queue\Jobs\JobName;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Psr\Log\LoggerInterface;
use Stomp\Transport\Frame;
Expand Down Expand Up @@ -105,8 +106,8 @@ public function getJobId()
public function fire()
{
$this->log->info("$this->session [STOMP] Executing event...");

$this->isNativeLaravelJob() ? $this->fireLaravelJob() : $this->fireExternalJob();
$this->ackIfNecessary();
}

protected function isNativeLaravelJob(): bool
Expand Down Expand Up @@ -220,15 +221,28 @@ protected function getBackoff(int $attempts): int
*/
protected function failed($e)
{
$this->ackIfNecessary();

// External events don't have failed method to call.
if (!$this->payload || !$this->isNativeLaravelJob()) {
return;
}

[$class, $method] = JobName::parse($this->payload['job']);

if (method_exists($this->instance = $this->resolve($class), 'failed')) {
$this->instance->failed($this->payload['data'], $e, $this->payload['uuid']);
try {
if (method_exists($this->instance = $this->resolve($class), 'failed')) {
$this->instance->failed($this->payload['data'], $e, $this->payload['uuid']);
}
} catch (\Exception $e) {
Log::error('Exception in job failing: ' . $e->getMessage());
}
}

protected function ackIfNecessary()
{
if (Config::get('consumer_ack_mode') == StompQueue::ACK_MODE_CLIENT && $this->frame) {
$this->stompQueue->client->ack($this->frame);
}
}
}

0 comments on commit 7385a3e

Please sign in to comment.