private function runSingleTask(Scheduler $scheduler, $task, OutputInterface $output) { try { $message = $scheduler->runTaskNow($task); } catch (\InvalidArgumentException $e) { $message = $e->getMessage() . PHP_EOL . 'Available tasks:' . PHP_EOL . implode(PHP_EOL, $scheduler->getTaskList()); throw new \Exception($message); } $output->writeln($message); }
/** * @dataProvider runDataProvider */ public function testRun($expectedTimetable, $expectedExecutedTasks, $timetableBeforeTaskExecution, $configuredTasks) { $taskLoader = $this->getMock('Piwik\\Scheduler\\TaskLoader'); $taskLoader->expects($this->atLeastOnce())->method('loadTasks')->willReturn($configuredTasks); // stub the piwik option object to control the returned option value self::stubPiwikOption(serialize($timetableBeforeTaskExecution)); $scheduler = new Scheduler($taskLoader, new NullLogger()); // execute tasks $executionResults = $scheduler->run(); // assert methods are executed $executedTasks = array(); foreach ($executionResults as $executionResult) { $executedTasks[] = $executionResult['task']; $this->assertNotEmpty($executionResult['output']); } $this->assertEquals($expectedExecutedTasks, $executedTasks); // assert the timetable is correctly updated $timetable = new Timetable(); $this->assertEquals($expectedTimetable, $timetable->getTimetable()); self::resetPiwikOption(); }
/** * Will run all scheduled tasks due to run at this time. * * @return array * @hideExceptForSuperUser */ public function runScheduledTasks() { Piwik::checkUserHasSuperUserAccess(); return $this->scheduler->run(); }
/** * @dataProvider runDataProvider */ public function testRunTaskNow($expectedTimetable, $expectedExecutedTasks, $timetableBeforeTaskExecution, $configuredTasks) { $taskLoader = $this->getMock('Piwik\\Scheduler\\TaskLoader'); $taskLoader->expects($this->atLeastOnce())->method('loadTasks')->willReturn($configuredTasks); // stub the piwik option object to control the returned option value self::stubPiwikOption(serialize($timetableBeforeTaskExecution)); $timetable = new Timetable(); $initialTimetable = $timetable->getTimetable(); $scheduler = new Scheduler($taskLoader, new NullLogger()); foreach ($configuredTasks as $task) { /** @var Task $task */ $result = $scheduler->runTaskNow($task->getName()); $this->assertNotEmpty($result); } // assert the timetable is NOT updated $this->assertSame($initialTimetable, $timetable->getTimetable()); self::resetPiwikOption(); }