feat: scheduled task success and failure notifications
This commit is contained in:
parent
96d4754a32
commit
99eea783ae
5 changed files with 12 additions and 9 deletions
|
|
@ -10,6 +10,7 @@
|
|||
use App\Models\Service;
|
||||
use App\Models\Team;
|
||||
use App\Notifications\ScheduledTask\TaskFailed;
|
||||
use App\Notifications\ScheduledTask\TaskSuccess;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
|
@ -111,6 +112,8 @@ public function handle(): void
|
|||
'message' => $this->task_output,
|
||||
]);
|
||||
|
||||
$this->team?->notify(new TaskSuccess($this->task, $this->task_output));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ public function link()
|
|||
return null;
|
||||
}
|
||||
|
||||
public function failedTaskLink($task_uuid)
|
||||
public function taskLink($task_uuid)
|
||||
{
|
||||
if (data_get($this, 'environment.project.uuid')) {
|
||||
$route = route('project.application.scheduled-tasks', [
|
||||
|
|
|
|||
|
|
@ -1140,7 +1140,7 @@ public function link()
|
|||
return null;
|
||||
}
|
||||
|
||||
public function failedTaskLink($task_uuid)
|
||||
public function taskLink($task_uuid)
|
||||
{
|
||||
if (data_get($this, 'environment.project.uuid')) {
|
||||
$route = route('project.service.scheduled-tasks', [
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ public function __construct(public ScheduledTask $task, public string $output)
|
|||
{
|
||||
$this->onQueue('high');
|
||||
if ($task->application) {
|
||||
$this->url = $task->application->failedTaskLink($task->uuid);
|
||||
$this->url = $task->application->taskLink($task->uuid);
|
||||
} elseif ($task->service) {
|
||||
$this->url = $task->service->failedTaskLink($task->uuid);
|
||||
$this->url = $task->service->taskLink($task->uuid);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
use App\Notifications\Dto\SlackMessage;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
|
||||
class TaskFailed extends CustomEmailNotification
|
||||
class TaskSuccess extends CustomEmailNotification
|
||||
{
|
||||
public ?string $url = null;
|
||||
|
||||
|
|
@ -16,9 +16,9 @@ public function __construct(public ScheduledTask $task, public string $output)
|
|||
{
|
||||
$this->onQueue('high');
|
||||
if ($task->application) {
|
||||
$this->url = $task->application->failedTaskLink($task->uuid);
|
||||
$this->url = $task->application->taskLink($task->uuid);
|
||||
} elseif ($task->service) {
|
||||
$this->url = $task->service->failedTaskLink($task->uuid);
|
||||
$this->url = $task->service->taskLink($task->uuid);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ public function toMail(): MailMessage
|
|||
{
|
||||
$mail = new MailMessage;
|
||||
$mail->subject("Coolify: Scheduled task ({$this->task->name}) succeeded.");
|
||||
$mail->view('emails.scheduled-task-failed', [
|
||||
$mail->view('emails.scheduled-task-success', [
|
||||
'task' => $this->task,
|
||||
'url' => $this->url,
|
||||
'output' => $this->output,
|
||||
|
|
@ -43,7 +43,7 @@ public function toMail(): MailMessage
|
|||
public function toDiscord(): DiscordMessage
|
||||
{
|
||||
$message = new DiscordMessage(
|
||||
title: ':check_mark: Scheduled task succeeded',
|
||||
title: ':white_check_mark: Scheduled task succeeded',
|
||||
description: "Scheduled task ({$this->task->name}) succeeded.",
|
||||
color: DiscordMessage::successColor(),
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue