task_uuid = $task_uuid; if ($application_uuid) { $this->type = 'application'; $this->application_uuid = $application_uuid; $this->resource = Application::ownedByCurrentTeam()->where('uuid', $application_uuid)->firstOrFail(); } elseif ($service_uuid) { $this->type = 'service'; $this->service_uuid = $service_uuid; $this->resource = Service::ownedByCurrentTeam()->where('uuid', $service_uuid)->firstOrFail(); } $this->parameters = [ 'environment_name' => $environment_name, 'project_uuid' => $project_uuid, 'application_uuid' => $application_uuid, 'service_uuid' => $service_uuid, ]; $this->task = $this->resource->scheduled_tasks()->where('uuid', $task_uuid)->firstOrFail(); $this->syncData(); } catch (\Exception $e) { return handleError($e); } } public function syncData(bool $toModel = false) { if ($toModel) { $this->validate(); $this->task->enabled = $this->isEnabled; $this->task->name = str($this->name)->trim()->value(); $this->task->command = str($this->command)->trim()->value(); $this->task->frequency = str($this->frequency)->trim()->value(); $this->task->container = str($this->container)->trim()->value(); $this->task->save(); } else { $this->isEnabled = $this->task->enabled; $this->name = $this->task->name; $this->command = $this->task->command; $this->frequency = $this->task->frequency; $this->container = $this->task->container; } } public function instantSave() { try { $this->syncData(true); $this->dispatch('success', 'Scheduled task updated.'); $this->refreshTasks(); } catch (\Exception $e) { return handleError($e); } } public function submit() { try { $this->syncData(true); $this->dispatch('success', 'Scheduled task updated.'); } catch (\Exception $e) { return handleError($e); } } public function refreshTasks() { try { $this->task->refresh(); } catch (\Exception $e) { return handleError($e); } } public function delete() { try { $this->task->delete(); if ($this->type === 'application') { return redirect()->route('project.application.configuration', $this->parameters, $this->task->name); } else { return redirect()->route('project.service.configuration', $this->parameters, $this->task->name); } } catch (\Exception $e) { return handleError($e); } } public function executeNow() { try { ScheduledTaskJob::dispatch($this->task); $this->dispatch('success', 'Scheduled task executed.'); } catch (\Exception $e) { return handleError($e); } } }