/** * singleton pattern * * @param boolean $verboseFlagFromSoapDaemon * * @return PlentySoapDaemonActionCollector */ public static function getInstance($verboseFlagFromSoapDaemon) { if (!isset(self::$instance) || !self::$instance instanceof PlentySoapDaemonActionCollector) { self::$instance = new PlentySoapDaemonActionCollector($verboseFlagFromSoapDaemon); } return self::$instance; }
/** * Control function * * @param array $params */ public function run() { /* * the daemon should only be running once! */ if ($this->checkPidFile()) { $this->getLogger()->crit(__FUNCTION__ . ' ERROR PlentySoapDaemon already running, shutting down!'); exit; } $this->writePidFile(); PlentySoapDaemonActionCollector::getInstance(self::VERBOSE)->loadActionObjectList(); while (true) { /* * can I execute an action? */ $soapActionList = PlentySoapDaemonActionCollector::getInstance(self::VERBOSE)->getNextActions(); if (isset($soapActionList) && is_array($soapActionList)) { /* * execute actions */ foreach ($soapActionList as $actionClassName) { $actionObject = PlentySoapDaemonActionCollector::getInstance(self::VERBOSE)->getActionObject($actionClassName); if (is_object($actionObject)) { $this->debug(__FUNCTION__ . ' START ' . $actionClassName . '->execute()'); $actionObject->execute(); $this->debug(__FUNCTION__ . ' END ' . $actionClassName . '->execute()'); $actionObject->setLastRunTimestamp(time()); } } } if ($this->stopDaemon === true) { $this->debug('I got a signal to shut down.'); $this->rmPidFile(); exit; } /* * sleep and run again... */ sleep(self::SLEEP); } }