Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I track progress on a queue job?

I am using the the database queue driver in laravel to run jobs in the background.

One of my jobs creates a given number (thousands to hundred thousands) records in the database. I wrapped the code for this job in a transaction so that in case the job failed, the database writes would not be commited.

Initially to track progress of the job, i thought i would count the number of created records, divide by total number of expected records then display that in a ui as percentage against each job such that users can know how much longer they have to wait.

This doesn't work because the tables are locked during the transaction.

Am wondering if anybody knows how track progress on a queued job

like image 865
Ernest Okot Avatar asked Oct 26 '15 23:10

Ernest Okot


People also ask

How do I see queued jobs in Linux?

DESCRIPTION The qstat command is used to request the status of jobs, queues, or a batch server. The requested status is written to standard out. When requesting job status, synopsis format 1, qstat will output information about each job_identifier or all jobs at each destination.

What are queues and jobs?

A job queue contains an ordered list of jobs waiting to be processed by a subsystem. The job queue is the first place that a submitted batch job goes before becoming active in a subsystem. The job is held here until a number of factors are met.

How do Laravel queues work?

Laravel queues provide a unified queueing API across a variety of different queue backends, such as Amazon SQS, Redis, or even a relational database. Laravel's queue configuration options are stored in your application's config/queue.php configuration file.


2 Answers

For the ones who stumble on this question, there is a package which allows that: https://github.com/imTigger/laravel-job-status

like image 117
Vincent Mimoun-Prat Avatar answered Sep 26 '22 15:09

Vincent Mimoun-Prat


As given in http://laravel.com/docs/5.1/queues#job-events

The Queue::after method can be called once a job has completed successfully

As given in http://laravel.com/docs/5.1/queues#failed-job-events

The Queue::failing method can be called when a queued job fails

Hope this is helpful :)

like image 30
ArtisanBay Avatar answered Sep 23 '22 15:09

ArtisanBay