2017-02-09 181 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到數據庫 –