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.