3

I have problem how to check if a Job is done or not. I am looking everywhere but i don't see that Laravel/Lumen has anything to work with, I am probably missing some. Example code:

$job = ((new FooJob($data)));
$jobID = dispatch($job);

if(is_numeric($jobID)) {
  while(elapsedTime < 10sec) {
    CHECK_JOB_SOMEHOW_IF_IS_DONE !?!
  }
}

I have installed https://github.com/gilbitron/laravel-queue-monitor which is really helping out, to save data on completed jobs. There i don't see anything either.

I have Lumen 5.4 framework.

Danijel
  • 817
  • 1
  • 17
  • 31

2 Answers2

1

I put out this solution:

When Job is done at the end of Job::Handle i put trough Redis a mark, for this specific job (set redis key "job:[ID_JOB]" val 1) and than in request part I am checking that Redis key when pop up, and that is it. It's working fine.

One other solution would be trough event system of lumen/laravel, to do a Redis mark, but for what I want it seem kinda bit overkill.

Danijel
  • 817
  • 1
  • 17
  • 31
-1

You will need to create the jobs and jobs_failed tables according to the documentation Queues - Lumen.

It will be necessary to create the queue.php file inside the app/config folder, follows the file template:

return [
    'default' => env('QUEUE_DRIVER', 'sync'),
    'connections' => [
        'sync' => [
            'driver' => 'sync',
        ],
        'database' => [
            'driver' => 'database',
            'table' => 'jobs',
            'queue' => 'default',
            'retry_after' => 60,
        ],
    ],
    'failed' => [
        'database' => env('QUEUE_CONNECTION', 'mysql'),
        'table' => 'jobs_failed',
    ], ];

After creating the tables, when using the method dispatch the information will be saved in the jobs table.

To process the queue use the command php artisan queue:work

rikardo_paiva
  • 393
  • 1
  • 5
  • This is actually not a problem that I have, all things for queue are working :) It's just a checking problem. – Danijel Aug 24 '17 at 06:15