/** * Updates an existing Task model. * If update is successful, the browser will be redirected to the 'index' page. * @param $id * @return string * @throws \yii\web\NotFoundHttpException */ public function actionUpdate($id) { /* @var $model Task|null */ $model = Task::find()->where(['id' => $id, 'type' => Task::TYPE_REPEAT])->one(); if ($model !== null) { $model->scenario = 'repeat'; if ($model->load($_POST) && $model->validate()) { $model->fail_counter = 0; if ($model->save()) { Yii::$app->session->setFlash('success', Yii::t('app', 'Record has been saved')); $returnUrl = Yii::$app->request->get('returnUrl', ['background/manage/index']); switch (Yii::$app->request->post('action', 'save')) { case 'next': return $this->redirect(['/background/manage/create', 'returnUrl' => $returnUrl]); case 'back': return $this->redirect($returnUrl); default: return $this->redirect(Url::toRoute(['/background/manage/update', 'id' => $model->id, 'returnUrl' => $returnUrl])); } } } else { return $this->render('update', ['model' => $model]); } } else { throw new NotFoundHttpException('repeated task #' . $id . ' not found'); } }
public function actionIndex() { $now = time(); /* @var $event Task[] */ $event = Task::find()->where(['type' => Task::TYPE_EVENT, 'status' => Task::STATUS_ACTIVE])->all(); /* @var $repeat Task[] */ $repeat = Task::find()->where(['type' => Task::TYPE_REPEAT, 'status' => Task::STATUS_ACTIVE])->all(); foreach ($event as $task) { $task->run(); } foreach ($repeat as $task) { if (BackgroundTasks::checkExpression($now, $task->cron_expression)) { $task->setProcess(); } } /* @var $process Task[] */ $process = Task::find()->where(['type' => Task::TYPE_REPEAT, 'status' => Task::STATUS_PROCESS])->all(); foreach ($process as $task) { $task->run(); } }