Queue :: later()在Laravel上不起作用

编程入门 行业动态 更新时间:2024-10-08 05:28:36
本文介绍了Queue :: later()在Laravel上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在研究Laravel框架,并且遇到一些队列问题. Laravel提供了一个统一的API来处理队列,我正在研究它. Laravel提供的方法之一是Queue::later(DateTime|int $delay, string $job, mixed $data = '', string $queue = null);

I am studying Laravel framework and I am facing some problems with queues. Laravel provides a unified API to work with queues and I am taking a look into it. One of the methods that Laravel provides is Queue::later(DateTime|int $delay, string $job, mixed $data = '', string $queue = null);

因此,我实现了我的工作课程:

So, I implemented my job class:

<?php class SendEmail { public function send($job, $data) { Log::info('JOB: ' . $job->getName()); Log::info('DATA: ' . $data['message']); } }

上面,我登录一个文件,接收到参数.只是想知道它是否有效.我的控制器使用队列API以这种方式调用作业:

Above, I log on a file, the parameters received. Just to know if it's working or not. My controller calls the job this way using Queue API:

<?php class MyControllerController extends BaseController { function index() { LOG::debug('Index action STARTED'); $date = Carbon::now()->addMinutes(2); Queue::later($date, 'SendEmail@send', array('message' => 'MY MESSAGE!')); $view = View::make('index'); LOG::debug('Index action FINISHED'); return $view; } }

看看我正在使用Queue::later().我希望类SendEmail的方法send()将在2分钟后执行. 好了,我完成了一个空白视图并设置了路线.然后我向控制器发出GET请求,然后去检查日志文件.

Take a look that I am using Queue::later(). I expected that method send() of class SendEmail would be executed after 2 minutes. Well, I finished to implement a blank view and set up the route. Then I made a GET request to my controller and I went to check the log file.

当我打开日志文件时看到了这一点:

I saw this when I opened the log file:

[2014-10-02 16:23:11] production.DEBUG: Index action STARTED [] [] [2014-10-02 16:23:11] production.INFO: JOB: [] [] [2014-10-02 16:23:11] production.INFO: DATA: MY MESSAGE! [] [] [2014-10-02 16:23:11] production.DEBUG: Index action FINISHED [] []

所有操作同时执行,包括作业. Queue::later()不会延迟执行.我认为我的日志文件应该是:

Everything executed at same time, inclusive the job. The Queue::later() is not delaying the execution. I think my log file should be:

[2014-10-02 16:23:11] production.DEBUG: Index action STARTED [] [] [2014-10-02 16:23:11] production.DEBUG: Index action FINISHED [] [] [2014-10-02 16:25:11] production.INFO: JOB: [] [] [2014-10-02 16:25:11] production.INFO: DATA: MY MESSAGE! [] []

我的代码怎么了?

推荐答案

对不起,刚刚发现我的错误.我正在使用sync驱动程序,这意味着在创建作业时将执行该作业.我打开/app/config/queue.php并发现:

Sorry, just found my mistake. I am using sync driver, which means the job is executed when the job is created. I opened my /app/config/queue.php and found:

'sync' => array( 'driver' => 'sync', ),

我会尝试使用beanstalkd.

更多推荐

Queue :: later()在Laravel上不起作用

本文发布于:2023-11-25 11:49:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629624.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上不   Queue   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!