<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sbourdette / laravel-mongo-queue-monitor example snippets
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use sbourdette\MongoQueueMonitor\Traits\IsMonitored; // <---
class ExampleJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
use IsMonitored; // <---
}
use Illuminate\Contracts\Queue\ShouldQueue;
use sbourdette\MongoQueueMonitor\Traits\IsMonitored;
class ExampleJob implements ShouldQueue
{
use IsMonitored;
public function handle()
{
$this->queueProgress(0);
// Do something...
$this->queueProgress(50);
// Do something...
$this->queueProgress(100);
}
}
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Collection;
use sbourdette\MongoQueueMonitor\Traits\IsMonitored;
class ChunkJob implements ShouldQueue
{
use IsMonitored;
public function handle()
{
$usersCount = User::count();
$perChunk = 50;
User::query()
->chunk($perChunk, function (Collection $users) use ($perChunk, $usersCount) {
$this->queueProgressChunk($usersCount‚ $perChunk);
foreach ($users as $user) {
// ...
}
});
}
}
use Illuminate\Contracts\Queue\ShouldQueue;
use sbourdette\MongoQueueMonitor\Traits\IsMonitored;
class LazyJob implements ShouldQueue
{
use IsMonitored;
public function progressCooldown(): int
{
return 10; // Wait 10 seconds between each progress update
}
}
use Illuminate\Contracts\Queue\ShouldQueue;
use sbourdette\MongoQueueMonitor\Traits\IsMonitored;
class CustomDataJob implements ShouldQueue
{
use IsMonitored;
public function handle()
{
$this->queueData(['foo' => 'Bar']);
// WARNING! This is overriding the monitoring data
$this->queueData(['bar' => 'Foo']);
// To preserve previous data and merge the given payload, set the $merge parameter true
$this->queueData(['bar' => 'Foo'], true);
}
}
'ui' => [
...
'show_custom_data' => true,
...
]
use Illuminate\Contracts\Queue\ShouldQueue;
use sbourdette\MongoQueueMonitor\Traits\IsMonitored;
class FrequentSucceedingJob implements ShouldQueue
{
use IsMonitored;
public static function keepMonitorOnSuccess(): bool
{
return false;
}
}
use sbourdette\MongoQueueMonitor\Models\Monitor;
$job = Monitor::query()->first();
// Check the current state of a job
$job->isFinished();
$job->hasFailed();
$job->hasSucceeded();
// Exact start & finish dates with milliseconds
$job->getStartedAtExact();
$job->getFinishedAtExact();
// If the job is still running, get the estimated seconds remaining
// Notice: This
use sbourdette\MongoQueueMonitor\Models\Monitor;
// Filter by Status
Monitor::failed();
Monitor::succeeded();
// Filter by Date
Monitor::lastHour();
Monitor::today();
// Chain Scopes
Monitor::today()->failed();