diff --git a/app/Jobs/ScheduledTaskJob.php b/app/Jobs/ScheduledTaskJob.php new file mode 100644 index 000000000..f810e746a --- /dev/null +++ b/app/Jobs/ScheduledTaskJob.php @@ -0,0 +1,77 @@ +task = $task; + if ($service = $task->service()->first()) { + $this->resource = $service; + } else if ($application = $task->application()->first()) { + $this->resource = $application; + } + } + + public function middleware(): array + { + return [new WithoutOverlapping($this->task->id)]; + } + + public function uniqueId(): int + { + return $this->task->id; + } + + public function handle(): void + { + file_put_contents('/tmp/scheduled-job-run', 'ran in handle'); + try { + echo($this->resource->type()); + file_put_contents('/tmp/scheduled-job-run-'.$this->task->id, $this->task->name); + } catch (\Throwable $e) { + send_internal_notification('ScheduledTaskJob failed with: ' . $e->getMessage()); + throw $e; + } finally { + // BackupCreated::dispatch($this->team->id); + } + } + private function add_to_backup_output($output): void + { + if ($this->backup_output) { + $this->backup_output = $this->backup_output . "\n" . $output; + } else { + $this->backup_output = $output; + } + } +} diff --git a/app/Models/ScheduledTaskExecution.php b/app/Models/ScheduledTaskExecution.php new file mode 100644 index 000000000..de13fefb0 --- /dev/null +++ b/app/Models/ScheduledTaskExecution.php @@ -0,0 +1,15 @@ +belongsTo(ScheduledTask::class); + } +} diff --git a/database/migrations/2024_01_01_231053_create_scheduled_task_executions_table.php b/database/migrations/2024_01_01_231053_create_scheduled_task_executions_table.php new file mode 100644 index 000000000..27ace08d4 --- /dev/null +++ b/database/migrations/2024_01_01_231053_create_scheduled_task_executions_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('uuid')->unique(); + $table->enum('status', ['success', 'failed', 'running'])->default('running'); + $table->longText('message')->nullable(); + $table->foreignId('scheduled_task_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('scheduled_task_executions'); + } +};