Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check to see if a job is in the Laravel queue?

Here's the situation:

I have a Laravel 4.2 application that retrieves (from a third party API) an asset. This is a long-lived asset (it only changes once every 12-24 hours) and is kind of time consuming (a large image file). I do cache the asset, so the impact has been more or less minimized, but there's still the case where the first person who logs in to my application in the morning has to wait while the application loads the asset for the first time.

I have set up a job which will be queued up and will run every eight hours. This ought to ensure that the asset in the cache is always fresh. It works by re-enqueueing the job for eight hours later after it runs.

The problem is this: I'm about to deploy this job system to production & I'm not sure how to start this thing running for the first time.

Ideally, I'd like to have an administration option where I have a button which says "Click here to submit the job", but I'd like to make it as foolproof as possible & prevent people (I'm not the only administrator) from submitting the job multiple times. To do this, however, the application would need to check & see if the job is already in the queue. I can't find a way to do that in an implementation-independent way (I'm using redis, but that may change in the future).

Another option would be to add an artisan command to run the initial process. That way I could deploy the application, run an artisan command, and forget about it.

So, to recap, I have two questions:

  1. Is there a way to check a queue to see what jobs are in there?

  2. Is there a better way to do this?

Thanks

like image 340
Kryten Avatar asked Feb 18 '15 18:02

Kryten


1 Answers

When a job is in laravel queue, it will be saved in jobs table, so you can check by DB.

like image 85
Beater Avatar answered Nov 13 '22 10:11

Beater