コード例 #1
0
ファイル: pear-manager.php プロジェクト: rjha/sc
 /**
  * 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"));
 }
コード例 #2
0
 function worker()
 {
     //check for args
     if (count($this->arguments) != 3) {
         $this->writeLine("Usage: worker schema_id function");
         exit;
     }
     $schema_id = $this->arguments[1];
     $function = $this->arguments[2];
     #define('NET_GEARMAN_JOB_PATH', "../../include/Net/Gearman/Job/" );
     require_once 'Net/Gearman/Worker.php';
     //create server array
     $servers = array();
     foreach (Doo::db()->find('GearmanJobServers', array('where' => "schema_id = {$schema_id}")) as $s) {
         $servers[] = $s->hostname . ":" . $s->port;
     }
     try {
         $worker = new Net_Gearman_Worker($servers);
         $worker->addAbility($function);
         $worker->beginWork();
     } catch (Net_Gearman_Exception $e) {
         echo $e->getMessage() . "\n";
         exit;
     }
 }
コード例 #3
0
 /**
  * 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"));
 }
コード例 #4
0
ファイル: Worker.php プロジェクト: sudevva/parser2
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $limit = $input->getArgument('limit');
     if ($limit > 1) {
         for (; $limit > 0; $limit--) {
             BackgroundProcess::open('php index.php worker:parse 1');
         }
     } else {
         if ($limit == 1) {
             try {
                 $worker = new \Net_Gearman_Worker($this->config->getGearmanHost());
                 $worker->addAbility('parse');
                 $worker->beginWork();
             } catch (\Net_Gearman_Exception $e) {
                 Logger::addMessage($e->getMessage());
                 BackgroundProcess::open('php index.php worker:parse 1');
             }
         }
     }
     FileLogger::save();
 }
コード例 #5
0
ファイル: worker.php プロジェクト: xing/gearman-ruby
<?php

error_reporting(E_ALL & ~E_NOTICE);
require_once 'Net/Gearman/Worker.php';
try {
    $worker = new Net_Gearman_Worker(array('localhost:4730'));
    $worker->addAbility('Sleep');
    $worker->beginWork();
} catch (Net_Gearman_Exception $e) {
    echo $e->getMessage() . "\n";
    exit;
}
コード例 #6
0
 public function beginWork($monitor = null)
 {
     $this->consumed = false;
     return parent::beginWork($monitor);
 }