Example #1
0
 public function execute(Job $job)
 {
     if (!$this->is_loaded) {
         require_once $this->ann['file'];
         $this->is_loaded = true;
         if ($this->ann->isMethod()) {
             $class = $this->ann['class'];
             $this->instance = [new $class(), $this->ann['method']];
         } else {
             $this->instance = $this->ann['function'] ?: $this->ann['class'];
         }
     }
     $worker = $this->instance;
     $job->begin();
     if (is_array($worker)) {
         return $worker[0]->{$worker[1]}[$ann['method']]($job->args, $job, $this->server);
     }
     return $worker($job->args, $job, $this->server);
 }
Example #2
0
 public function listen()
 {
     $job = $this->conn->reserve();
     $this->conn->delete($job);
     return Job::restore($this->config, $job->getData());
 }
Example #3
0
 public function listen()
 {
     $this->get('GearmanWorker')->work();
     return Job::restore($this->config, $this->workload);
 }
Example #4
0
 public function listen()
 {
     if (empty($this->sql)) {
         throw new \RuntimeException("You need to add services first");
     }
     $tasks = $this->conn->tasks;
     do {
         $this->sql->execute($this->args);
         $task = $tasks->findOneByTaskHandleAndTaskStatus($this->handle, 1);
         if ($task) {
             $task->taskStatus = 2;
             $this->conn->save($task);
             break;
         }
         usleep(200000);
     } while (true);
     return Job::restore($this->config, $task->taskPayload);
 }
Example #5
0
 public function listen()
 {
     $this->channel->basic_qos(null, 1, null);
     $this->channel->wait();
     return Job::restore($this->config, $this->msg->body);
 }
Example #6
0
 protected function processReport($process, $stdout)
 {
     foreach (explode("\n", $stdout) as $line) {
         if (empty($line)) {
             continue;
         }
         if ($line[0] == "") {
             $parts = explode("", $line);
             if ($parts[2] != strlen($parts[3])) {
                 die("Invalid response");
             }
             $args = json_decode($parts[3], true);
             switch ($parts[1]) {
                 case 'start':
                     $process->status = 'busy';
                     $process->job = Job::restore($this->config, $args['args']);
                     $process->time = time();
                     $process->timeout = max($args['timeout'], 60);
                     $this->log($process, "beging job '{$process->job->function}'");
                     break;
                 case 'failed':
                     $process->job = null;
                     $process->status = 'idle';
                     $process->time = time();
                     $process->failed++;
                     if (empty($process->memory_begin)) {
                         $process->memory_begin = $args[0];
                     }
                     $process->memory_last = $args[1];
                     $this->log($process, "done with error ({$args[2]}: {$args[3]})");
                     $this->checkprocessHealth($process);
                     break;
                 case 'end':
                     $process->job->setResult($args[0]);
                     $process->job = null;
                     $process->status = 'idle';
                     $process->time = time();
                     $process->jobs++;
                     if (empty($process->memory_begin)) {
                         $process->memory_begin = $args[1];
                     }
                     $process->memory_last = $args[2];
                     $this->log($process, "done with success");
                     $this->checkprocessHealth($process);
                     break;
                 case 'empty':
                     $this->log($process, "no job, respawning in {$args[0]} seconds");
                     break;
             }
         } else {
             $this->log($process, $line);
         }
     }
 }