romanzipp / Laravel-Queue-Monitor

Monitoring Laravel Jobs with your Database
https://packagist.org/packages/romanzipp/laravel-queue-monitor
MIT License
660 stars 91 forks source link

supervisor handle jobs but without Laravel-Queue-Monitor #137

Closed kirklandstar closed 8 months ago

kirklandstar commented 10 months ago

Laravel-Queue-Monitor works good with running manually But when I use supervisor jobs run but without Laravel-Queue-Monitor

Laravel 8 Laravel-Queue-Monitor 2.3

romanzipp commented 10 months ago

I don't have a magic orb to tell you what you're doing wrong. Please provide any information on architecture, code snippets, error logs, expected behavior, configuration, ...

kirklandstar commented 10 months ago

newsProcessingData::dispatch($data, $file_path)->onQueue('news_processing');

Job File

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

use \Storage;

use romanzipp\QueueMonitor\Traits\IsMonitored;

class newsProcessingData implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    use IsMonitored;

    protected $batch;
    protected $file_path;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($batch, $file_path)
    {
        $this->batch = $batch;
        $this->file_path = $file_path;
    }

    /**
     * The number of times the job may be attempted.
     *
     * @var int
     */
    public $tries = 3;
    public $timeout = 600;

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $json_data = json_encode($this->batch);
        Storage::disk('python-php')->put($this->file_path, $json_data);
        print_r('created file '.$this->file_path);
    }
}

supervisor config

[program:laravel-worker-news-processing]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work --queue news_processing --sleep=3 --tries=10 --timeout=30
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/news_processing.log
stopwaitsecs=3600

When I started job manually - php artisan queue:work --queue=news_processing Job has finished sucessfully with creating record in queue_monitor table

When I started job with supervisor Job has finished sucessfully but without creating record in queue_monitor table

romanzipp commented 10 months ago

Try setting the working directory in the supervisor job config.

directory=/var/www/html
command=php artisan queue:work --queue news_processing --sleep=3 --tries=10 --timeout=30