Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StompJob #36

Merged
merged 7 commits into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading