/** * Checks for the stop condition of this strategy * * @param WorkerEvent $event * @return string */ public function onStopConditionCheck(WorkerEvent $event) { if ($this->interrupted) { $event->exitWorkerLoop(); $this->state = sprintf("interrupt by an external signal on '%s'", $event->getName()); } }
/** * @param WorkerEvent $event * @return void */ public function onStopConditionCheck(WorkerEvent $event) { if ($event->getName() == WorkerEvent::EVENT_PROCESS_IDLE) { if ($this->previousIdlingTime + $this->idleThrottleTime > microtime(true)) { return; } else { $this->previousIdlingTime = microtime(true); } } if (!count($this->files)) { $this->constructFileList(); $this->state = sprintf("watching %s files for modifications", count($this->files)); } foreach ($this->files as $checksum => $file) { if (!file_exists($file) || !is_readable($file) || (string) $checksum !== hash_file('crc32', $file)) { $event->exitWorkerLoop(); $this->state = sprintf("file modification detected for '%s'", $file); } } }
/** * Callback facilitating the worker loop * * It simulates a process queue strategy. And triggers an idle event on every uneven invokation of the PROCESS event * * @param WorkerEvent $e */ public function callbackWorkerLoopEvents(WorkerEvent $e) { if (!isset($this->actualCalled[$e->getName()])) { $this->actualCalled[$e->getName()] = 1; } else { $this->actualCalled[$e->getName()]++; } // mark for exit when event is due if ($e->getName() == $this->exitedBy && $this->actualCalled[$e->getName()] >= $this->exitAfter) { $e->exitWorkerLoop(); } // simulate process queue strategy, trigger idle event on every uneven call if ($e->getName() == WorkerEvent::EVENT_PROCESS_QUEUE) { if (!($this->actualCalled[WorkerEvent::EVENT_PROCESS_QUEUE] % 2)) { $e->getTarget()->getEventManager()->trigger(WorkerEvent::EVENT_PROCESS_IDLE, $e); $e->stopPropagation(); return; } } }