Queue :: later()在Laravel上不起作用 [英] Queue::later() not working on Laravel

查看:129
本文介绍了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上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆