lundi 31 mai 2021

Accessing SQS job data (receipt handle) from a Laravel queued console command

I'm adding functionality to a pre-existing app, using Laravel 5.8.38 and the SQS queue driver.

I'm looking for a way to log the receipt handle of queue messages as they're processed, so that we can manually delete messages from the queue for jobs that have gone horribly wrong (without the receipt ID, we'd have to wait for the visibility timeout to be reached).

I'm not super familiar with Laravel and am trying to figure things out as I go. We have two types of queued jobs:

  • a custom class implementing Illuminate\Contracts\Queue\ShouldQueue, that also uses the Illuminate\Queue\InteractsWithQueue, Illuminate\Foundation\Bus\Dispatchable and Illuminate\Bus\Queueable traits (our class gets queued directly)
  • a custom command, extending Illuminate\Console\Command, that runs via Illuminate\Foundation\Console\QueuedCommand

For the custom class, browsing through the source for InteractsWithQueue and Illuminate/Queue/Jobs/SqsJob I discovered I could access the receipt handle directly:

$sqsJob = $this->job->getSqsJob();
\Log::info("Processing SQS job {$sqsJob["MessageId"]} with handle {$sqsJob["ReceiptHandle"]}");

This works great! However, I can't figure out how to do a similar thing from the console command.

Laravel's QueuedCommand implements ShouldQueue as well as Illuminate\Bus\Queueable, so my current guess is that I'll need to extend this, use InteractsWithQueue, and retrieve and log the receipt handle from there. However if I do that, I can't figure out how I would modify Artisan::queue('app:command', $commandOptions); to queue my custom QueuedCommand class instead.

Am I almost there? If so, how can I queue my custom QueuedCommand class instead of the Laravel one? Or, is there a better way to do this?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3fXrQtJ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire