public function testRun() { $type = 'testType'; $this->taskRunnerSupervisorProphecy->markRunnerStart()->willReturn(); $this->taskRunnerSupervisorProphecy->shouldRunnerStop()->will(function () { $this->shouldRunnerStop()->will(function () { $this->shouldRunnerStop()->will(function () { $this->shouldRunnerStop()->willReturn(true); return false; }); return false; }); return false; }); $queueRunMethodProphecy = $this->createPropheciesForTaskRunnerRun($type); $queueRunMethodProphecy->shouldBeCalledTimes(4); $this->sut->run($type); }
public function execute() { global $wgDevelEnvironment, $wgFlowerUrl; if ($wgDevelEnvironment) { \Wikia\Logger\WikiaLogger::instance()->setDevModeWithES(); } \Wikia\Logger\WikiaLogger::instance()->pushContext(['task_id' => $this->mOptions['task_id']]); $runner = new TaskRunner($this->mOptions['wiki_id'], $this->mOptions['task_id'], $this->mOptions['task_list'], $this->mOptions['call_order'], $this->mOptions['created_by']); ob_start(); $runner->run(); $result = $runner->format(); if ($runner->runTime() > TaskRunner::TASK_NOTIFY_TIMEOUT) { Http::post("{$wgFlowerUrl}/api/task/status/{$this->mOptions['task_id']}", ['noProxy' => true, 'postData' => json_encode(['kwargs' => ['completed' => time(), 'state' => $result->status, 'result' => $result->status == 'success' ? $result->retval : $result->reason]])]); } ob_end_clean(); echo json_encode($result); }
for ($i = 1; $i <= 6; $i++) { $data = yield; echo '<p>Tâche 2, itération ' . $i . ', valeur envoyée : ' . $data . '</p>'; } } function task3() { for ($i = 1; $i <= 4; $i++) { $data = yield; echo '<p>Tâche 3, itération ' . $i . ', valeur envoyée : ' . $data . '</p>'; } } $taskRunner->addTask(task1()); $taskRunner->addTask(task2()); $taskRunner->addTask(task3()); $taskRunner->run(); ?> </p> <h2>La méthode throw()</h2> <p><strong>Lancer une exception à l'emplacement du <code>yield</code> dans le générateur - accepte un seul argument</strong></p> <p class="col-sm-12"> <?php // Génére une fatal error - normal - une exception est lancée par PHP // function generator3() { // echo "<p>Début</p>"; // yield; // echo "<p>Fin</p>"; // }
fwrite(STDERR, 'Could not locate autoload.php.'); exit(1); } require $autoloadPath; use Icicle\Concurrent\Exception\{ChannelException, SerializationException}; use Icicle\Concurrent\Sync\{ChannelledStream, Internal\ExitFailure, Internal\ExitSuccess}; use Icicle\Concurrent\Worker\{BasicEnvironment, Internal\TaskRunner}; use Icicle\Coroutine; use Icicle\Loop; use Icicle\Stream; Coroutine\create(function () { $channel = new ChannelledStream(Stream\stdin(), Stream\stdout()); $environment = new BasicEnvironment(); $runner = new TaskRunner($channel, $environment); try { $result = new ExitSuccess(yield from $runner->run()); } catch (Throwable $exception) { $result = new ExitFailure($exception); } // Attempt to return the result. try { try { return yield from $channel->send($result); } catch (SerializationException $exception) { // Serializing the result failed. Send the reason why. return yield from $channel->send(new ExitFailure($exception)); } } catch (ChannelException $exception) { // The result was not sendable! The parent context must have died or killed the context. return 0; }