/** * Wrapper function handler for all registered functions * This allows us to do some nice logging when jobs are started/finished * * @see https://github.com/brianlmoon/GearmanManager/blob/ffc828dac2547aff76cb4962bb3fcc4f454ec8a2/GearmanPeclManager.php#L95-206 * * @param \GearmanJob $job * @param mixed $context * * @return mixed */ public function handleJob(\GearmanJob $job) { if (!isset($this->workersBucket[$job->functionName()])) { $context = false; } else { $context = $this->workersBucket[$job->functionName()]; } if (!is_array($context) || !array_key_exists('job_object_instance', $context) || !array_key_exists('job_method', $context)) { throw new \InvalidArgumentException('$context shall be an array with job_object_instance and job_method key.'); } $event = new GearmanWorkStartingEvent($context['jobs']); $this->eventDispatcher->dispatch(GearmanEvents::GEARMAN_WORK_STARTING, $event); $result = call_user_func_array(array($context['job_object_instance'], $context['job_method']), array($job, $context)); /** * Workaround for PECL bug #17114 * http://pecl.php.net/bugs/bug.php?id=17114 */ $type = gettype($result); settype($result, $type); return $result; }
/** * Get gearman API called command name. * * @return string */ public function getCommandName() { return $this->_job->functionName(); }