Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Queued Laravel jobs all fire simultaneously, and don't show up in the jobs table

I am using Laravel queues for commenting on Facebook posts. Whenever I receive data from a Facebook webhook, based on the received details I comment on the post. To handle 100 responses at once from Facebook webhooks, I am using Laravel queues, so that it can execute one by one. I used the step by step process as mentioned in 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 the webhooks() function continuously, and all the jobs are working simultaneously but not in the queue. None of the jobs are being stored in the jobs table. I have given a delay but it is also not working.

And this is my 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 
like image 662
Punabaka Abhinav Avatar asked Feb 09 '17 10:02

Punabaka Abhinav


People also ask

How do I know if my Laravel queue is working?

$this->mailer->queue($view, $data, function ($message) use ($toEmail, $toName, $subject) { $message ->to($toEmail, $toName) ->subject($subject); }); This will successfully run, but if the queue is not 'listening', the job gets pushed on to the job table, forever. I am looking for something like \Queue::isListening();

What is the difference between job and queue in Laravel?

Jobs and QueuesThe line itself is the Queue, and each customer in the line is a Job. In order to process Jobs in the Queue you need command line processes or daemons. Think of launching a queue daemon on the command line as adding a new bank teller to the pool of available bank tellers.

What is sync queue Laravel?

Sync, or synchronous, is the default queue driver which runs a queued job within your existing process. With this driver enabled, you effectively have no queue as the queued job runs immediately.


1 Answers

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 for make sure that no config cached

php artisan config:clear 

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

like image 195
Mahdi Youseftabar Avatar answered Sep 17 '22 00:09

Mahdi Youseftabar