public function schedulerShutdownHandler()
 {
     $error = error_get_last();
     if ($this->taskRunner && E_ERROR == $error['type']) {
         $this->taskRunner->handleError($error['type'], $error['message'], $error['file'], $error['line']);
     }
 }
 public function testRunAllPassesParamsCoreecltyTwo()
 {
     $mock = $this->getMock('TaskInterface', array('execute'));
     $mock->expects($this->exactly(2))->method('execute')->with($this->equalTo(array('foo')), $this->greaterThanOrEqual(0));
     $runner = new TaskRunner();
     $runner->registerTask($mock);
     $runner->registerTask($mock);
     $runner->runAll(array('foo'));
 }
 public function execute()
 {
     $wikis = $this->getWikisToFix();
     $corporateModel = new WikiaCorporateModel();
     foreach ($wikis as $wiki) {
         $wikiLocalImage = $this->getCVImage($wiki['city_id']);
         if (!empty($wikiLocalImage)) {
             try {
                 $corpWikiId = $corporateModel->getCorporateWikiIdByLang($wiki['city_lang_code']);
             } catch (Exception $e) {
                 var_dump($wiki['city_id'], $wiki['city_lang_code']);
             }
             $t = GlobalTitle::newFromText('Wikia-Visualization-Main.png', NS_FILE, $wiki['city_id']);
             if (TaskRunner::isModern('PromoteImageReviewTask')) {
                 $task = new \Wikia\Tasks\Tasks\PromoteImageReviewTask();
             } else {
                 $task = new PromoteImageReviewTask();
             }
             var_dump($t->getArticleID(), $wiki['city_main_image'], $corpWikiId, $wiki['city_id']);
             $res = $task->uploadSingleImage($t->getArticleID(), 'Wikia-Visualization-Main.png', $corpWikiId, $wiki['city_id']);
             if ($res['status'] == 0 && !empty($res['name'])) {
                 var_dump($res);
                 $this->updateVisualizationMainImageName($wiki['city_id'], $res['name']);
             }
         }
     }
 }
 public function execute($exec_args)
 {
     /*
      * The first item is always the filename.
      */
     array_shift($exec_args);
     $this->parseExecArgs($exec_args);
     // This will do for now, but really this should be wrapped in a class
     // and all actions should register themselves with that class.
     if (isset($exec_args) && count($exec_args) > 0) {
         $action = array_shift($exec_args);
         $args = $exec_args;
         if ($action_info = TaskRunner::parseActionInfo($action)) {
             list($obj, $file) = $action_info;
         }
     }
     if (!isset($obj)) {
         $action = 'help';
         if ($action_info = TaskRunner::parseActionInfo($action)) {
             list($obj, $file) = $action_info;
         }
         $args = array();
     }
     $this->action = $action;
     require_once $file;
     print $this->preFormat();
     $action_object = new $obj(array('options' => &$this->options));
     print $this->postFormat($action_object->execute($args));
 }
Example #5
0
 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);
 }
 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 showHelp($args = array())
 {
     if ($action_info = TaskRunner::parseActionInfo($args[0])) {
         list($obj, $file) = $action_info;
     }
     if (isset($obj)) {
         require_once $file;
         return $obj::getHelp();
     }
 }
 function tasks()
 {
     return TaskRunner::create();
 }
 public static function onCreatePromoteImageReviewTask($type, $list)
 {
     if (empty($list)) {
         return true;
     }
     if (TaskRunner::isModern('PromoteImageReviewTask')) {
         $batch = [];
         foreach ($list as $targetWikiId => $wikis) {
             $taskList = new \Wikia\Tasks\AsyncTaskList();
             $task = new \Wikia\Tasks\Tasks\PromoteImageReviewTask();
             $call = $task->call($type, $targetWikiId, $wikis);
             $taskList->add($call);
             $batch[] = $taskList;
         }
         \Wikia\Tasks\AsyncTaskList::batch($batch);
     } else {
         $task = new PromoteImageReviewTask();
         $key = $type == 'delete' ? 'deletion_list' : 'upload_list';
         $params = [$key => $list];
         $task->createTask($params, TASK_QUEUED);
     }
     return true;
 }
    {
        // Tant qu’il y a toujours au moins une tâche à exécuter
        while (!$this->tasks->isEmpty()) {
            // On enlève la première tâche et on la récupère au passage
            $task = $this->tasks->dequeue();
            // On exécute la prochaine étape de la tâche
            $task->send('Hello world !');
            // Si la tâche n’est pas finie, on la replace en fin de liste
            if ($task->valid()) {
                $this->addTask($task);
            }
        }
    }
}
// Tester la class
$taskRunner = new TaskRunner();
function task1()
{
    for ($i = 1; $i <= 2; $i++) {
        $data = yield;
        echo '<p>Tâche 1, itération ' . $i . ', valeur envoyée : ' . $data . '</p>';
    }
}
function task2()
{
    for ($i = 1; $i <= 6; $i++) {
        $data = yield;
        echo '<p>Tâche 2, itération ' . $i . ', valeur envoyée : ' . $data . '</p>';
    }
}
function task3()
Example #11
0
 /**
  * Creates a new task runner.
  *
  * @param TaskCollection       $collection
  * @param LoggerInterface|null $logger
  *
  * @return TaskRunner
  */
 public function create(TaskCollection $collection, LoggerInterface $logger = null)
 {
     $taskRunner = new TaskRunner();
     $taskRunner->setTaskCollection($collection);
     if ($logger) {
         $taskRunner->setLogger($logger);
     }
     $this->logger->debug('Attaching deployment output handler to events.');
     $taskRunner->on('runner.start', array($this->deploymentOutputHandler, 'onRunnerStart'));
     $taskRunner->on('runner.success', array($this->deploymentOutputHandler, 'onRunnerSuccess'));
     $taskRunner->on('runner.task.start', array($this->deploymentOutputHandler, 'onTaskStart'));
     $taskRunner->on('runner.task.success', array($this->deploymentOutputHandler, 'onTaskSuccess'));
     $taskRunner->on('runner.task.retry', array($this->deploymentOutputHandler, 'onTaskRetry'));
     $taskRunner->on('runner.task.skip', array($this->deploymentOutputHandler, 'onTaskSkip'));
     $taskRunner->on('runner.task.unless', array($this->deploymentOutputHandler, 'onTaskUnless'));
     return $taskRunner;
 }
Example #12
0
}
if (null === $autoloadPath) {
    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.
 /**
  * Test update process statistics
  */
 public function testUpdateStatistics()
 {
     $TaskClient = $this->getMock('TaskClient');
     $TaskServer = $this->getMock('TaskServer', array('stopped', 'started', 'updated', 'mustStop'));
     $TaskServer->useDbConfig = 'test';
     $TaskServer->expects($this->once())->method('started');
     $TaskServer->expects($this->once())->method('stopped');
     $TaskServer->expects($this->any())->method('updated');
     $TaskServer->expects($this->any())->method('mustStop')->will($this->returnValue(false));
     $Shell = $this->getMock('Shell', array('out', 'err'));
     $task = array('id' => 1, 'path' => '', 'command' => $this->executable, 'arguments' => array('-f' => $this->_code2File('$a = array(); while(count($a) < 20000){ $a = array_merge($a, array(new stdClass));}')), 'timeout' => 100);
     $TaskRunner = new TaskRunner($task, $TaskServer, $TaskClient, $Shell);
     $runnedTask = $TaskRunner->start();
     $statistics = ClassRegistry::init('Task.TaskStatistics')->find('all', array('conditions' => array('task_id' => $runnedTask['id'])));
     $this->assertGreaterThan(1, count($statistics));
     $statisticsOne = $statistics[count($statistics) - 1]['TaskStatistics'];
     $this->assertGreaterThan(0, (double) $statisticsOne['memory']);
     $this->assertGreaterThan(0, (double) $statisticsOne['cpu']);
     $this->assertNotEmpty($statisticsOne['status']);
 }