I needed a package to monitor my job queue and I found this cool package, I tried it and found that the monitor doesn't show any data after trying to run the job. I have added traits to my job class.
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Log;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use romanzipp\QueueMonitor\Traits\IsMonitored;
class SendNotification implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, IsMonitored;
protected $topics;
protected $notification;
public $tries = 5;
public $backoff = 3;
public function __construct(array $topics, $notification = "")
{
$this->topics = $topics;
$this->notification = $notification;
}
public function handle()
{
Log::info('Job started', ['time' => now()->toDateTimeString()]);
foreach ($this->topics as $i => $topic) {
if ($i > 0) {
sleep(3);
}
try {
Log::info('Notifikasi berhasil dikirim', ['topic' => $topic, 'time' => now()->toDateTimeString()]);
} catch (\Exception $e) {
Log::error('Gagal mengirim notifikasi', ['topic' => $topic, 'error' => $e->getMessage(), 'time' => now()->toDateTimeString()]);
}
}
Log::info('Job finished', ['time' => now()->toDateTimeString()]);
}
}
Hey! So your problem as far as I understood is that no data is being logged with the Monitor model? For this, you can call the queueData() method on the job class after applying the trait
I needed a package to monitor my job queue and I found this cool package, I tried it and found that the monitor doesn't show any data after trying to run the job. I have added traits to my job class.