public function executeAction() { Assert::found($id = (int) $this->dispatcher->getParam('0', 'uint')); Assert::found($task = Task::findFirst($id), "Task not found"); $job = Job::findFirst(['task_id = ?0 and executed_at is null', 'bind' => [$task->task_id]]); if (!$job) { $job = new Job(); $job->save(['task_id' => $task->task_id]); Assert::noMessages($job); } return $this->response->redirect('/task/run/' . $job->job_id, true); }