在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):romanzipp/Laravel-Queue-Monitor开源软件地址(OpenSource Url):https://github.com/romanzipp/Laravel-Queue-Monitor开源编程语言(OpenSource Language):PHP 79.4%开源软件介绍(OpenSource Introduction):Laravel Queue MonitorThis package offers monitoring like Laravel Horizon for database queue. Features
Installation
ConfigurationCopy configuration & migration to your project:
Migrate the Queue Monitoring table. The table name can be configured in the config file or via the published migration.
UsageTo monitor a job, simply add the use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use romanzipp\QueueMonitor\Traits\IsMonitored; // <---
class ExampleJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
use IsMonitored; // <---
} Important! You need to implement the UIYou can enable the optional UI routes by calling Route::prefix('jobs')->group(function () {
Route::queueMonitor();
}); Routes
See the full configuration file for more information. Extended usageProgressYou can set a progress value (0-100) to get an estimation of a job progression. use Illuminate\Contracts\Queue\ShouldQueue;
use romanzipp\QueueMonitor\Traits\IsMonitored;
class ExampleJob implements ShouldQueue
{
use IsMonitored;
public function handle()
{
$this->queueProgress(0);
// Do something...
$this->queueProgress(50);
// Do something...
$this->queueProgress(100);
}
} Chunk progressA common scenario for a job is iterating through large collections. This example job loops through a large amount of users and updates it's progress value with each chunk iteration. use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Collection;
use romanzipp\QueueMonitor\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) {
// ...
}
});
}
} Progress cooldownTo avoid flooding the database with rapidly repeating update queries, you can set override the use Illuminate\Contracts\Queue\ShouldQueue;
use romanzipp\QueueMonitor\Traits\IsMonitored;
class LazyJob implements ShouldQueue
{
use IsMonitored;
public function progressCooldown(): int
{
return 10; // Wait 10 seconds between each progress update
}
} Custom dataThis package also allows setting custom data in array syntax on the monitoring model. use Illuminate\Contracts\Queue\ShouldQueue;
use romanzipp\QueueMonitor\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);
}
} In order to show custom data on UI you need to add this line under 'ui' => [
...
'show_custom_data' => true,
...
] Only keep failed jobsYou can override the use Illuminate\Contracts\Queue\ShouldQueue;
use romanzipp\QueueMonitor\Traits\IsMonitored;
class FrequentSucceedingJob implements ShouldQueue
{
use IsMonitored;
public static function keepMonitorOnSuccess(): bool
{
return false;
}
} Retrieve processed Jobsuse romanzipp\QueueMonitor\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 requires a progress to be set
$job->getRemainingSeconds();
$job->getRemainingInterval(); // Carbon\CarbonInterval
// Retrieve any data that has been set while execution
$job->getData();
// Get the base name of the executed job
$job->getBasename(); Model Scopesuse romanzipp\QueueMonitor\Models\Monitor;
// Filter by Status
Monitor::failed();
Monitor::succeeded();
// Filter by Date
Monitor::lastHour();
Monitor::today();
// Chain Scopes
Monitor::today()->failed(); UpgradingThis package was inspired by gilbitron's laravel-queue-monitor which is not maintained anymore. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论