Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if job in in Beanstalkd queue has been completed in Laravel

I need to check if job added to queue (Beanstalkd) has been completed in Laravel (Laravel 5) and in case it's completed I need to return updated record (task added to queue updates record in database). I've added to my composer.json:

"pda/pheanstalk": "3.*"

I add job to queue this way:

$jobId = Queue::push('App\Class', $object->toArray(), $this->getQueueName());

I use to check if job was completed using is the following function:

public function find($queueName, $jobId, $recordId)
{
    $phean = Queue::getPheanstalk();

    try {
        $phean->peek($jobId);
        $data = ['status' => 'waiting'];
    } catch (ServerException $e) {
        $message = $e->getMessage();

        if ($message == 'NOT_FOUND: Job ' . $jobId . ' does not exist.') {
            $data = ... // here I get from database data for $recordId

        } else {
            $data = ['status' => 'error'];
        }
    }

    return $data;
}

The question is - is that reliable method to check if job has been completed? I compare here just message I get from exception. I haven't found any other way to check if job has been completed.

like image 381
Marcin Nabiałek Avatar asked Jan 11 '15 14:01

Marcin Nabiałek


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();

How do I know if Beanstalk is running?

Check with $ sudo service beanstalkd status to see if the server is already running. If it is not running, start it with $ sudo service beanstalkd start command.

How do I retry failed jobs in Laravel?

You can even retry all jobs at once by executing the php artisan queue:retry --all command. Alternatively, if you want to retry failed jobs from a certain queue, you can execute the php artisan queue:retry --queue=high-priority command.

What is Dispatch in Laravel queue?

Dispatching jobs to queue using the command bus gives you extra control; you can set the selected connection , queue , and delay from within your job class, decide if the command should be queued or run instantly, send the job through a pipeline before running it, actually you can even handle the whole queueing process ...


1 Answers

I haven't used Laravel 5 yet, but on Laravel 4, you have the failed jobs table. Where you can see which jobs DIDN'T complete. I'm assuming that L5 might have something or keep the same process. That wouldn't solve your problem?

From my point of view it seems that you are only inverting the perspective. Instead of looking for what failed, you are looking for what worked.

Source

like image 123
Eduardo Cruz Avatar answered Nov 09 '22 23:11

Eduardo Cruz