2024-05-21 13:36:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications\ScheduledTask;
|
|
|
|
|
|
|
|
use App\Models\ScheduledTask;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
|
|
|
|
class TaskFailed extends Notification implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Queueable;
|
|
|
|
|
|
|
|
public $backoff = 10;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-05-21 13:36:26 +00:00
|
|
|
public $tries = 2;
|
|
|
|
|
|
|
|
public ?string $url = null;
|
|
|
|
|
|
|
|
public function __construct(public ScheduledTask $task, public string $output)
|
|
|
|
{
|
|
|
|
if ($task->application) {
|
|
|
|
$this->url = $task->application->failedTaskLink($task->uuid);
|
2024-06-10 20:43:34 +00:00
|
|
|
} elseif ($task->service) {
|
2024-05-21 13:36:26 +00:00
|
|
|
$this->url = $task->service->failedTaskLink($task->uuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function via(object $notifiable): array
|
|
|
|
{
|
|
|
|
|
|
|
|
return setNotificationChannels($notifiable, 'scheduled_tasks');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toMail(): MailMessage
|
|
|
|
{
|
|
|
|
$mail = new MailMessage();
|
|
|
|
$mail->subject("Coolify: [ACTION REQUIRED] Scheduled task ({$this->task->name}) failed.");
|
|
|
|
$mail->view('emails.scheduled-task-failed', [
|
|
|
|
'task' => $this->task,
|
|
|
|
'url' => $this->url,
|
|
|
|
'output' => $this->output,
|
|
|
|
]);
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-05-21 13:36:26 +00:00
|
|
|
return $mail;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toDiscord(): string
|
|
|
|
{
|
|
|
|
return "Coolify: Scheduled task ({$this->task->name}, [link]({$this->url})) failed with output: {$this->output}";
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-05-21 13:36:26 +00:00
|
|
|
public function toTelegram(): array
|
|
|
|
{
|
|
|
|
$message = "Coolify: Scheduled task ({$this->task->name}) failed with output: {$this->output}";
|
|
|
|
if ($this->url) {
|
|
|
|
$buttons[] = [
|
2024-06-10 20:43:34 +00:00
|
|
|
'text' => 'Open task in Coolify',
|
|
|
|
'url' => (string) $this->url,
|
2024-05-21 13:36:26 +00:00
|
|
|
];
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-05-21 13:36:26 +00:00
|
|
|
return [
|
2024-06-10 20:43:34 +00:00
|
|
|
'message' => $message,
|
2024-05-21 13:36:26 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|