Laravel queues not working

Punabaka Abhinav picture Punabaka Abhinav · Feb 9, 2017 · Viewed 48.6k times · Source

I am using laravel queues for commenting on the facebook post. When ever i recieve data from facebook webhook, based on the recieved details i am commenting on the post. To handle 100 responses at once from facebook webhook i am using laravel queues, so that it can execute one by one. I have used the step by step process as mentioned in https://scotch.io/tutorials/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");
}

and this is my job class structure

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 
}

}

I am hitting webhooks() function continuously, all the jobs are working simultaneously but not in queue, none of the jobs are storing in jobs table, i have given delay but it is also not working, please some one help me, I have been trying from yesterday, but no result.

And this is my log in 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

Answer

Mahdi Youseftabar picture Mahdi Youseftabar · Feb 9, 2017

for use queue you should some work :

in .env file you should change queue_driver from sync to database, so open .env and do the follow

queue_driver=database

after it you should create queue table in your database with artisan command :

php artisan queue:table
php artisan migrate

and finally you should run your queue with php artisan queue:listen or php artisan queue:work