function run($options = array())
 {
     $this->init($options);
     if ($poolPid = $this->shm->get(0)) {
         $this->logger->debug("Get process pool pid from shm. pid: '{$poolPid}'");
     } else {
         $poolPid = 0;
     }
     if ($this->poolIsRunning($poolPid)) {
         $this->logger->info(sprintf("Cronjob '%s' is already running (pid: %d)", $this->jobName, $poolPid));
         if ($this->worker) {
             $this->logger->info("Enqueue work...");
             $queue = $this->processPool->workQueue;
             if (($cap = $queue->capacity()) && $this->config['waitPrevComplete']) {
                 $this->logger->warn(sprintf("Another cronjob is not complete (%d pending tasks)", $cap));
                 return;
             }
             // Enqueue tasks
             $this->worker->enqueueWork($queue);
             posix_kill($poolPid, SIGUSR1);
         }
         return;
     }
     $this->processPool->start();
 }
Exemple #2
0
 function run($options = null)
 {
     $this->init($options);
     // Check that process pool is running
     try {
         $poolPid = $this->nodeRegistry->get(self::REGKEY_MAIN_PROCESS_PID);
     } catch (Exception $e) {
         $this->logger->warn(sprintf("Caught: <%s> %s. Let the process pool is not started", get_class($e), $e->getMessage()));
         $poolPid = 0;
     }
     if ($this->poolIsRunning($poolPid)) {
         // and i'm a leader node ...
         if ($this->nodeName == $this->zookeeper->getData("{$this->jobZPath}/leader")) {
             if (!$this->checkMemoryLimit()) {
                 return;
             }
             // Enqueue work
             $this->worker->enqueueWork($this->globalWorkQueue);
         }
         return;
     }
     $this->processPool->start();
 }
Exemple #3
0
 function terminate()
 {
     if ($this->worker) {
         $this->worker->terminate();
     }
 }