Esempio n. 1
0
 public function perform(Job $job)
 {
     echo "starting job\n";
     sleep(5);
     $job->heartbeat();
     echo "still jobbing\n";
     sleep(2);
     echo "job's done\n";
     $job->complete();
 }
Esempio n. 2
0
 private function watchdogStart()
 {
     $socket = null;
     $this->watchdogPID = $this->fork($socket);
     if ($this->watchdogPID !== 0) {
         $this->sockets[$this->watchdogPID] = $socket;
         return;
     }
     $this->processType = self::PROCESS_TYPE_WATCHDOG;
     $this->clearSigHandlers();
     $jid = $this->job->getId();
     $this->who = 'watchdog:' . $this->workerName;
     $this->logContext = ['type' => $this->who];
     $status = 'watching events for ' . $jid . ' since ' . strftime('%F %T');
     $this->updateProcLine($status);
     $this->logger->info($status, $this->logContext);
     ini_set("default_socket_timeout", -1);
     $l = $this->client->createListener(['ql:log']);
     $l->messages(function ($channel, $event) use($l, $jid) {
         if (!in_array($event->event, ['lock_lost', 'canceled', 'completed', 'failed']) || $event->jid !== $jid) {
             return;
         }
         switch ($event->event) {
             case 'lock_lost':
                 if ($event->worker === $this->workerName) {
                     $this->logger->info("{type}: sending SIGKILL to child {$this->childPID}; job handed out to another worker", $this->logContext);
                     posix_kill($this->childPID, SIGKILL);
                     $l->stop();
                 }
                 break;
             case 'canceled':
                 if ($event->worker === $this->workerName) {
                     $this->logger->info("{type}: sending SIGKILL to child {$this->childPID}; job canceled", $this->logContext);
                     posix_kill($this->childPID, SIGKILL);
                     $l->stop();
                 }
                 break;
             case 'completed':
             case 'failed':
                 $l->stop();
                 break;
         }
     });
     socket_close($socket);
     $this->logger->info("{type}: done", $this->logContext);
     exit(0);
 }
Esempio n. 3
0
 public function perform(Job $job)
 {
     $data = $job->getData();
     $jid = $job->getId();
     echo $jid . "\n";
     //        throw new \Exception('Something bad, man');
     sleep(5);
     $job->heartbeat();
     sleep(5);
     $job->heartbeat();
     sleep(5);
     $job->requeue(['data' => ['time' => time(), 'thing' => ['blah' => 'foo']]]);
     return false;
 }
Esempio n. 4
0
 public function perform(Job $job)
 {
     $job->complete();
 }
Esempio n. 5
0
 public function process(Job $job, array $payload)
 {
     $this->logger->info('workin on job: ' . $job->getId() . ' with payload: ' . json_encode($payload));
     $job->complete();
 }
Esempio n. 6
0
 public function performSendTemplate(Job $job, $params)
 {
     $this->sendTemplate($params['to'], $params['fromEmail'], $params['fromName'], $params['subject'], $params['template'], $params['parameters'], $params['cc'], $params['bcc']);
     $job->complete();
 }