phpsymfonygearman

Retrieving results from background Gearman job/task


Subject is quite self-explanatory, but I definitely need a fresh pair of eyes on this.

I am using mmoreram/GearmanBundle Symfony2 bundle to send jobs to execute. So, far I have managed to send a job, execute it and return results. That part works as expected.

However, I am trying to the same with background job/tasks. I know that, in this scenario, client does not wait for job to complete, but I was hoping that job handle can help me with that (e.g. retrieve job status).

$gearman = $this->get('gearman');
$jobId = $gearman->doHighBackgroundJob("CsvWorker~parseCsv", json_encode(["foo", "bar", "123"]));
sleep(3);

// At this point, job has completed for sure (it's very simple)
var_dump($jobId);
var_dump($gearman->getJobStatus($jobId));

This outputs the following:

string 'H:localhost.localdomain:10' (length=26)

object(Mmoreram\GearmanBundle\Module\JobStatus)[410]
  private 'known' => boolean false
  private 'running' => boolean false
  private 'completed' => int 0
  private 'completionTotal' => int 0

The known => false, in particular, really puzzles me. During the job execution, I made sure to invoke correctly sendStatus and sendComplete methods.

So, I guess, a general question would be: once the job has completed, is it still known to Gearman?

UPDATE:

I managed to add some code changes to the bundle which allowed me to listen for data being returned by job. That way, I may be able to persist that in database, however, my client (job creator) is still pretty much left in the dark on whether the job has actually finished.


Solution

  • As described in PHP Manual, as long as the job is known to the server, it is not completed.