PHP code example of alveby / laravel-queue-manager
1. Go to this page and download the library: Download alveby/laravel-queue-manager 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/ */
alveby / laravel-queue-manager example snippets
use AlveBy\QueueManager\Facades\QueueManager;
QueueManager::cancel($uuid, reason: 'user aborted the export');
QueueManager::pause('export', until: now()->addMinutes(10));
QueueManager::search()->tag('client:123')->get();
$result = QueueManager::cancel($uuid, 'user aborted the export');
$result->wasRemoved(); // true: it was still queued and is now gone
$result->isDeferred(); // true: a worker will drop it instead
$result->state; // where it was: pending, delayed, reserved, or null
use AlveBy\QueueManager\Concerns\Cancellable;
class ExportJob implements ShouldQueue
{
use Cancellable;
public function handle(): void
{
foreach ($this->rows()->chunk(500) as $chunk) {
if ($this->cancelled()) {
return;
}
$this->export($chunk);
}
}
}
use AlveBy\QueueManager\Middleware\SkipIfCancelled;
public function middleware(): array
{
return [new SkipIfCancelled];
}
use AlveBy\QueueManager\Contracts\Taggable;
class ExportJob implements ShouldQueue, Taggable
{
public function __construct(public int $clientId) {}
public function queueTags(): array
{
return ['client:'.$this->clientId, 'tenant:'.tenant()->id];
}
}
QueueManager::delete($uuid); // remove without flagging cancelled
QueueManager::runNow($uuid); // delayed -> available now
QueueManager::reschedule($uuid, now()->addHour()); // move a pending or delayed job
QueueManager::purge('export'); // drop pending + delayed
QueueManager::counts('export'); // ['pending' => n, 'delayed' => n, 'reserved' => n]
QueueManager::stats(); // one row per queue, with pause state
QueueManager::queues();