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.
$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();
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.
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.
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 ...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With