Laravel-Queue-Monitor icon indicating copy to clipboard operation
Laravel-Queue-Monitor copied to clipboard

does this package still work, and is it relevant to laravel 8.x

Open halimkun opened this issue 1 year ago • 1 comments

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()]);
    }
}

halimkun avatar Jun 28 '24 04:06 halimkun

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

romanzipp avatar Jun 28 '24 08:06 romanzipp