gpt4 book ai didi

php - 排队的 Laravel 作业全部同时触发,并且不会显示在作业表中

转载 作者:行者123 更新时间:2023-12-02 19:18:14 26 4
gpt4 key购买 nike

我正在使用 Laravel 队列来评论 Facebook 帖子。每当我从 Facebook webhook 收到数据时,我都会根据收到的详细信息对该帖子发表评论。为了一次处理来自 Facebook webhooks 的 100 个响应,我使用 Laravel 队列,以便它可以逐一执行。我使用了Why Laravel Queues Are Awesome中提到的逐步过程。

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
{
use InteractsWithQueue, SerializesModels;

private $data;

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

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

我连续点击webhooks()函数,所有作业都在同时工作,但不在队列中。作业表中没有存储任何作业。我已经给出了延迟,但它也不起作用。

这是我的 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

最佳答案

要使用队列,您应该做一些工作:

在 .env 文件中,您应该将queue_driver从同步更改为数据库,所以打开 .env 并执行以下操作

queue_driver=database

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

php artisan queue:table
php artisan migrate

并确保没有缓存配置

php artisan config:clear

最后,您应该使用 php artisanqueue:listenphp artisanqueue:work

运行队列

关于php - 排队的 Laravel 作业全部同时触发,并且不会显示在作业表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42133628/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com