public function _test_tryingToKillScript() { if ('Windows' == substr(php_uname(), 0, 7)) { $this->setExpectedExceptionRegExp('Zend\\ServiceManager\\Exception\\ServiceNotCreatedException'); } $worker = $this->container->get($this->workerServiceName); $pId = $worker->call(['delay' => 10]); $this->assertTrue($worker->isProcessWorking($pId)); // $itemData = [ // 'pid' => $pId, // 'startedAt' => UTCTime::getUTCTimestamp(), // 'scriptName' => 'Worker: tryingToKillScript', // 'timeout' => 30 // ]; // $this->dataStore->create($itemData); // Trying to kill script posix_kill($pId, 9); // Give script the time for dying sleep(1); // Checks it $this->assertFalse($worker->isProcessWorking($pId)); sleep(6); // Five records in the log: plus records after previous test // and in this test script won't write the entry: it was killed $this->assertEquals(5, $this->dataStore->count()); }
protected function setUp() { $this->container = (include './config/container.php'); $this->log = $this->container->get('tick_log_datastore'); $this->log->deleteAll(); $this->initCallback(); }
public function test_callCallable() { $promise = $this->decorator->asyncCall(['rpc_callback' => ['\\zaboy\\test\\scheduler\\Examples\\Callback\\SimpleClass', 'staticMethodWhichLogsOneRow'], 'tick_id' => time(), 'step' => 1]); $this->assertEquals($promise->getState(), $promise::PENDING); sleep(2); $this->assertEquals($promise->getState(), $promise::FULFILLED); $this->assertEquals(1, $this->log->count()); }
public function test_checkProcess() { // Let finish to processes sleep(2); /** @var \zaboy\scheduler\Broker\ScriptBroker $broker */ $broker = $this->container->get('script_broker'); $broker->checkProcess(); $this->assertEquals(1, $this->pidsDataStore->count()); sleep(30); $broker->checkProcess(); $this->assertEquals(0, $this->pidsDataStore->count()); }
public function test_scriptProxy() { // Clear log before testing $this->log->deleteAll(); $callbackManager = $this->container->get('callback_manager'); /** @var \zaboy\scheduler\Callback\Script $scriptCallback */ $scriptProxyCallback = $callbackManager->get('test_scriptproxy_callback'); $options = ['param1' => 'value1', 'param2' => ['value21', 'value22']]; $scriptProxyCallback->call($options); // Expected that in the log will be one entry $item = $this->log->read(1); $this->assertEquals(print_r($options, 1), $item['step']); // Clear log again $this->log->deleteAll(); }
/** * This test may not work in virtual environment like windows web-server (denwer, openserver etc) or vbox virtual machines */ public function test_clearLog() { // Add limits for log files $totalTime = 3; $this->setTicker(['total_time' => $totalTime, 'step' => 0.1, 'tick__max_log_rows' => 30, 'hop__max_log_rows' => 1, 'critical_overtime' => 100]); $this->ticker->start(); sleep($totalTime); $this->assertEquals(30, $this->tickLog->count()); $this->assertEquals(1, $this->hopLog->count()); }
public function test_createFilterTask() { /** @var \zaboy\scheduler\Scheduler\Scheduler $scheduler */ $scheduler = $this->container->get('scheduler'); $filterData = $scheduler->create(['rql' => 'eq(tp_seconds,0)', 'callback' => function () { return 'ky'; }, 'active' => 1]); $callbackServiceNameFromDataStore = $this->filterDs->read($filterData['id'])['callback']; $this->assertEquals($filterData['callback'], $callbackServiceNameFromDataStore); $filterData = $scheduler->read($filterData['id']); $callback = $filterData['callback']; $this->assertEquals('ky', $callback()); }
/** * {@inherit} * * {@inherit} */ public function call(array $options = []) { $cmd = "php " . $this->script; $cmd .= Script::makeParamsString(['scriptOptions' => Script::encodeParams($options)]); $cmd .= " > /dev/null 2>&1 & echo \$!"; $output = trim(shell_exec($cmd)); if (!is_numeric($output)) { throw new CallbackException("The output of the script is ambiguous. Probably there is an error in the script"); } $pId = intval($output); $itemData = ['pid' => $pId, 'startedAt' => UTCTime::getUTCTimestamp(), 'scriptName' => "Worker: ", 'timeout' => 30]; $this->dataStore->create($itemData); return $pId; }
/** * {@inheritdoc} * * {@inheritdoc} */ public function count() { return parent::count(); }
/** * {@inherit} * * {@inherit} */ public function query(Query $query) { $this->setStep($this->determineStep($query)); $this->determineFrom($query); return parent::query($query); }
/** * Translates the "deleteAll" call to DataStore * * @see \zaboy\scheduler\Callback\Factory\DataStoreAbstractFactory * @see \zaboy\rest\DataStore\Interfaces\DataStoresInterface * @param array $options * @return int|null */ private function deleteall(array $options = []) { return $this->dataStore->deleteAll(); }
/** * Fills table by data from config * * TODO: уйдет из этого класса, пока не известно, куда, но здесь этого кода быть не должно * * @param ContainerInterface $serviceLocator * @throws DataStoreException */ protected function fillTable(ContainerInterface $container, DataStoreAbstract $dataStore) { $config = $container->get('config'); // If configs for tasks doesn't exist do nothing if (!isset($config[self::KEY_TASKS])) { return; } $id = $dataStore->getIdentifier(); foreach ($config[self::KEY_TASKS] as $task) { if (!isset($task[$id])) { throw new DataStoreException("Expected necessary parameter \"{$id}\" in data of filter"); } $dataStore->create($task); } }