2017-02-09 8 views
2

私はfacebook投稿にコメントするためにlaravel queuesを使用しています。私がFacebookのwebhookからデータを受信すると、受信した詳細に基づいて、私は の投稿にコメントしています。 facebook webhookから一度に100の応答を処理するために、私はlaravelのキューを使用していますので、1つずつ実行できます。 https://scotch.io/tutorials/why-laravel-queues-are-awesomeLaravel queues not working

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

私のログです:あなたはそれの後に同期からデータベース

にqueue_driveを変更する必要があります.envファイルに

職人のコマンドでデータベースにキューテーブルを作成する必要があります。

php artisan queue:table 
php artisan migrate 

そして最後に、あなたは私はあなたがすでにキュー表を持っていることを見ていphp artisan queue:listenまたはphp artisan queue:work

+0

はい、私はこれを行いました。これは、データが処理されている間に、何もphp artisan:listenコマンドの後に来ました。 –

+0

私は解決策を得ました、私はデータベースにqueue_driveを変更しませんでした。 –

+0

@Mahdi - ねえ、コマンドは 'php artisan queue:listen'ではなく' php artisan:listen'でなければなりません – TipuZaynSultan

1

を使用してキューを実行する必要があります。

php artisan queue:listen --tries=3またはphp artisan queue:workなど

キューの作業はコマンドごとに1つだけのジョブを実行するためのものである実行してみてください。したがって、テーブルに20のジョブがある場合、キュー作業を20回実行する必要があります。そのため、queue:listenコマンドを実行できます。しかし、それは多くのCPUを食べる。

サーバーでは、待ち行列を最大3回のバックグラウンドで試してみるとよいでしょう。 ターミナル/コマンドプロンプトでサーバーにSSHを送信します。次に、職人のファイルが存在するプロジェクトディレクトリにCDを入力します。このコマンドを実行します。この場合、求人

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

は自動的にバックグラウンドで処理されます。あなたは仕事を派遣するだけです。そして、私は失敗したジョブテーブルを使用することをお勧めします。バックグラウンドキューリスナーを使用している場合

これが役に立ちます。

+0

返信ありがとう、私はソリューションを持っている、私はデータベースにqueue_drive変更didnt –