/** * Starts a worker for the PEAR library * * @param array $worker_list List of worker functions to add * @return void * */ protected function start_lib_worker($worker_list) { /** * Require PEAR Net_Gearman libs */ define('NET_GEARMAN_JOB_PATH', $this->worker_dir); if (!class_exists("Net_Gearman_Job_Common")) { require "Net/Gearman/Job/Common.php"; } if (!class_exists("Net_Gearman_Job")) { require "Net/Gearman/Job.php"; } require "Net/Gearman/Worker.php"; $worker = new Net_Gearman_Worker($this->servers); foreach ($worker_list as $w) { $this->log("Adding job {$w}", GearmanManager::LOG_LEVEL_WORKER_INFO); $worker->addAbility($w); } $worker->attachCallback(array($this, 'job_start'), Net_Gearman_Worker::JOB_START); $worker->attachCallback(array($this, 'job_complete'), Net_Gearman_Worker::JOB_COMPLETE); $worker->attachCallback(array($this, 'job_fail'), Net_Gearman_Worker::JOB_FAIL); $this->start_time = time(); $this->job_execution_count++; $worker->beginWork(array($this, "monitor")); }
/** * Starts a worker for the PEAR library * * @param array $worker_list List of worker functions to add * @param array $timeouts list of worker timeouts to pass to server * @return void * */ protected function start_lib_worker($worker_list, $timeouts = array()) { /** * Require PEAR Net_Gearman libs */ define('NET_GEARMAN_JOB_PATH', $this->worker_dir); if (!class_exists("Net_Gearman_Job_Common")) { require "Net/Gearman/Job/Common.php"; } if (!class_exists("Net_Gearman_Job")) { require "Net/Gearman/Job.php"; } if (!class_exists("Net_Gearman_Worker")) { require "Net/Gearman/Worker.php"; } $worker = new Net_Gearman_Worker($this->servers); foreach ($worker_list as $w) { $timeout = isset($timeouts[$w]) ? $timeouts[$w] : null; $message = "Adding job {$w}"; if ($timeout) { $message .= "; timeout: {$timeout}"; } $this->log($message, GearmanManager::LOG_LEVEL_WORKER_INFO); $worker->addAbility($w, $timeout, $this->functions[$w]); } $worker->attachCallback(array($this, 'job_start'), Net_Gearman_Worker::JOB_START); $worker->attachCallback(array($this, 'job_complete'), Net_Gearman_Worker::JOB_COMPLETE); $worker->attachCallback(array($this, 'job_fail'), Net_Gearman_Worker::JOB_FAIL); $this->start_time = time(); $worker->beginWork(array($this, "monitor")); }