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

Marcin Nabiałek picture Marcin Nabiałek · Jan 11, 2015 · Viewed 7.3k times · Source

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.

Answer

Eduardo Cruz picture Eduardo Cruz · Jan 13, 2015

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