public function testInstance() { $schedule = new Schedule(); $schedule->exec('ls -a'); $schedule->command('migrate'); $schedule->call(function () { echo 'hello'; }); $this->assertEquals(3, count($schedule->events)); return $schedule; }
public function actionRun() { $this->stdout(PHP_EOL); $this->importScheduleFile(); /** @var Event[] $events */ $events = $this->schedule->dueEvents(Yii::$app); foreach ($events as $event) { $this->stdout('Runing scheduled command ' . $event->getSummaryForDisplay() . PHP_EOL); $event->run(Yii::$app); } if (count($events) == 0) { $this->stdout('No scheduled commands are ready to run.' . PHP_EOL); } }
/** * {@inheritdoc} */ public function init() { if (Yii::$app->has($this->schedule)) { $this->schedule = Instance::ensure($this->schedule, Schedule::className()); } else { $this->schedule = Yii::createObject(Schedule::className()); } parent::init(); }