php - 从作业队列内部广播 laravel 事件
问题描述
已经好几天了,我被困在广播活动中。
我有 - AWS 弹性豆茎设置。- 推杆配置有以下配置
BROADCAST_DRIVER=pusher
QUEUE_DRIVER=database
运行一个 laravel 主管。
使用 Laravel 5.5版
- 一份工作即
ConvertVideoForStreaming
- 一个事件即
VideoProcessingStarted
此事件被称为作业在后端开始处理。
它适用于我在本地使用
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 服务器上的主管上尝试它时,它们只是被内部作业忽略了。
解决方案
推荐阅读
- javascript - Javascript href 导航到不属于我的其他 url 然后自动滚动到一个类
- python - 让所有边连接到 NetworkX 中多向图中的一组节点的最快方法?
- regex - 如何使用.htaccess将带有查询字符串的url重定向到带有查询字符串的另一个url
- terraform - 使用 terraform-cloudflare 提供程序的 Cloudflare 页面规则不会更新页面规则
- javascript - addEventListener 输入键码不起作用
- python-3.x - 矩阵乘法 Python
- xcode - 无法在与 Xcode 断开连接的设备上运行我的应用程序
- c# - Analyzer + Code Fix 不生成选项
- python - 检查输入是否在 url 列表中
- node.js - 如何实时更新api?