PHP code example of boring-o11y / unique-job-middleware
1. Go to this page and download the library: Download boring-o11y/unique-job-middleware library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
boring-o11y / unique-job-middleware example snippets
use BoringO11y\UniqueJobMiddleware\Middleware\EnsureUniqueLock;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
class RecalculateInvoice implements ShouldQueue, ShouldBeUnique
{
public function __construct(public int $invoiceId) {}
public function uniqueId(): string
{
return (string) $this->invoiceId;
}
public function middleware(): array
{
return [new EnsureUniqueLock];
}
}
use BoringO11y\UniqueJobMiddleware\Events\UniqueJobSkipped;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
Event::listen(function (UniqueJobSkipped $event) {
Log::warning('Skipped a duplicate unique job', [
'job' => $event->job->resolveName(),
'job_id' => $event->job->uuid(),
'lock' => $event->lockKey,
]);
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.