2017-02-09 184 views
2

我正在使用laravel队列在facebook上发表评论。当我从facebook的webhook接收数据时,基于接收到的细节,我对 发表了评论。为了一次处理来自facebook webhook的100个响应,我使用laravel队列,以便它可以逐个执行。 我已经使用了一步步的过程,如https://scotch.io/tutorials/why-laravel-queues-are-awesomeLaravel队列不能正常工作

public function webhooks(Request $request) 
{ 
    $data = file_get_contents('php://input'); 
     Log::info("Request Cycle with Queues Begins"); 
     $job = (new webhookQueue($data)->delay(10); 
     $this->dispatch($job); 
     Log::info("Request Cycle with Queues Ends"); 
} 

提到,这是我的作业类结构

class webhookQueue extends Job implements ShouldQueue 

{

使用InteractsWithQueue,SerializesModels;

private $data; 

public function __construct($data) 
{ 
    $this->data = $data; 
} 

public function handle() 
{ 
    //handling the data here 
} 

}

我打网络挂接()函数不断,所有的任务都在队列同时但不工作,没有任何工作都存储在工作表中,我已经给了延迟,但它也是不工作,请有人帮助我,我一直试图从昨天开始,但没有结果。

这是我的日志中laravel.log

[2017-02-08 14:18:42] local.INFO: Request Cycle with Queues Begins 
[2017-02-08 14:18:44] local.INFO: Request Cycle with Queues Begins 
[2017-02-08 14:18:47] local.INFO: Request Cycle with Queues Begins 
[2017-02-08 14:18:47] local.INFO: Request Cycle with Queues Begins 
[2017-02-08 14:18:47] local.INFO: Request Cycle with Queues Begins 
[2017-02-08 14:18:47] local.INFO: Request Cycle with Queues Begins 
[2017-02-08 14:18:48] local.INFO: Request Cycle with Queues Begins 
[2017-02-08 14:18:48] local.INFO: Request Cycle with Queues Begins 
[2017-02-08 14:18:48] local.INFO: Request Cycle with Queues Begins 
[2017-02-08 14:18:48] local.INFO: Request Cycle with Queues Begins 
[2017-02-08 14:18:48] local.INFO: Request Cycle with Queues Begins 
[2017-02-08 14:18:48] local.INFO: Request Cycle with Queues Begins 
[2017-02-08 14:18:55] local.INFO: Request Cycle with Queues Ends 
[2017-02-08 14:18:55] local.INFO: Request Cycle with Queues Ends 
[2017-02-08 14:18:55] local.INFO: Request Cycle with Queues Ends 
[2017-02-08 14:18:59] local.INFO: Request Cycle with Queues Ends 
[2017-02-08 14:19:00] local.INFO: Request Cycle with Queues Ends 
[2017-02-08 14:19:00] local.INFO: Request Cycle with Queues Ends 
[2017-02-08 14:19:00] local.INFO: Request Cycle with Queues Ends 
[2017-02-08 14:19:01] local.INFO: Request Cycle with Queues Ends 
[2017-02-08 14:19:01] local.INFO: Request Cycle with Queues Ends 
[2017-02-08 14:19:01] local.INFO: Request Cycle with Queues Ends 
[2017-02-08 14:19:01] local.INFO: Request Cycle with Queues Ends 
[2017-02-08 14:19:01] local.INFO: Request Cycle with Queues Ends 

回答

5

使用队列,你应该找个工作

在.ENV文件,你应该从queue_drive同步之后将其更改为数据库

您应该使用artisan命令在数据库中创建队列表:

php artisan queue:table 
php artisan migrate 

,最后你应该运行你的队列php artisan queue:listenphp artisan queue:work

+0

是的,我已经做了这个,后php的工匠:侦听命令,而数据正在处理,什么都没有进入cmd提示 –

+0

我有解决方案,我没有改变queue_drive数据库,谢谢你的答复。 –

+0

@Mahdi - 嘿,命令应该是'php工匠队列:听'不是'php工匠:听' – TipuZaynSultan

1

我看到你已经有队列表。

尝试运行php artisan queue:listen --tries=3php artisan queue:work

队列工作是用于执行每个指令只有一个工作。因此,如果表中有20个作业,则可能需要运行20次队列工作。这就是为什么你可以运行queue:listen命令。但它吃了很多CPU。

在服务器中,您可能想要在后台运行最多3次尝试的队列侦听。 在终端/命令提示符下将SSH连接到您的服务器。然后将CD添加到工匠文件所在的项目目录中。运行此命令:

nohup php artisan queue:listen --tries=3 > /dev/null 2>&1 &

在这种情况下作业将在后台自动进行处理。你只需要派遣这份工作。我会建议使用失败作业表。如果您正在使用后台队列列表程序。

希望这会有所帮助。

+0

谢谢你的回复,我有解决方案,我没有改变queue_drive到数据库 –