首页 > 解决方案 > 从作业队列内部广播 laravel 事件

问题描述

已经好几天了,我被困在广播活动中。

我有 - AWS 弹性豆茎设置。- 推杆配置有以下配置 BROADCAST_DRIVER=pusher QUEUE_DRIVER=database

此事件被称为作业在后端开始处理。

它适用于我在本地使用

php artisan queue:work --timeout=0 --tries=1

但是当我尝试使用主管时,作业被执行,但从内部作业调用的事件没有被调度。

我仍然不确定为什么要这样做,使用 artisan 命令在本地工作,但不能使用在 aws 服务器上运行的主管。

弹性 beantalk 的主管配置:

[supervisord]
   logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
   logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
   logfile_backups=10           ; (num of main logfile rotation backups;default 10)
   loglevel=info                ; (log level;default info; others: debug,warn,trace)
   pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
   nodaemon=false               ; (start in foreground if true;default false)
   minfds=1024                  ; (min. avail startup file descriptors;default 1024)
   minprocs=20                 ; (min. avail process descriptors;default 200)

   [rpcinterface:supervisor]
   supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

   [supervisorctl]
   serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

   [program:queue]
   command=php artisan queue:work database --tries=3 --timeout=0 --queue=notifications,default
   directory=/var/app/current
   stdout_logfile=/var/app/current/storage/logs/supervisor.log
   redirect_stderr=true

事件类:VideoProcessingStarted

class VideoProcessingStarted implements ShouldBroadcastNow
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $videoID;
    public $offerID;
//    public $queue = 'notifications'; //Queue Name

    public function __construct($video)
    {
        $this->videoID = $video->id;
        $this->offerID = $video->offer->id;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('videos-processing.'.$this->videoID);
    }
}

工作:ConvertVideoForStreaming

class ConvertVideoForStreaming implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $video;
    public $disk;
    public $dateTimeStringNow;

    public function __construct(OfferLibrary $video,$disk)
    {
        $this->video = $video;
        $this->disk = $disk;
        $this->dateTimeStringNow = Carbon::now()->toDateTimeString();
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        /*
         * TotalJobStatuses
         * 1 - queue (meaning processing is pending)
         * 2 - processing (job has been started and in progress)
         * 3 - success (job has been processed and got completed successfully)
         * 4 - failed (job has been processed, but failed to complete)
         * */
        event(new VideoProcessingStarted($this->video));
        event(new VideoProcessingFailed($this->video->id));
        event(new VideoProcessingQueued($this->video));
        \Log::info('this should work, why not working, i dont know.::'.$this->video->id);
        return null;
}

工作中的事件被完全忽略,没有错误。

event(new VideoProcessingStarted($this->video));
            event(new VideoProcessingFailed($this->video->id));
            event(new VideoProcessingQueued($this->video));

但是最后一个日志信息行将被执行并记录在 laravel.log 文件中

\Log::info('this should work, why not working, i dont know.::'.$this->video->id);

我不知道为什么,但是事件在本地机器上运行良好,但是当我在 aws 服务器上的主管上尝试它时,它们只是被内部作业忽略了。

标签: phpmysqllaravelamazon-web-services

解决方案


推荐阅读