-
app/Notifications/ServerProvisioningFailed.php
Open in GitHubuse Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Markdown; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; class ServerProvisioningFailed extends Notification implements ShouldQueue { use Queueable; public function __construct( public string $serverName, public string $output = '', public string $errorMessage = '', ) { // } public function via(object $notifiable): array { return ['mail']; } public function toMail(object $notifiable): MailMessage { return (new MailMessage) ->line(__("The server ':name' failed to provision. We've deleted it for you, but you might have to manually remove it from your provider.", ['name' => $this->serverName])) ->when($this->output, function (MailMessage $message) { $message ->line(__("Here you'll find the 10 last lines of the task that failed:")) ->line(Markdown::parse("```{$this->output}```")); }) ->when($this->errorMessage, function (MailMessage $message) { $message ->line(__('This is the error message we received:')) ->line(Markdown::parse("```{$this->errorMessage}```")); }); } }
-
app/Jobs/CleanupFailedServerProvisioning.php
Open in GitHubuse App\Models\Server; use App\Models\Task; use App\Notifications\ServerProvisioningFailed; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; class CleanupFailedServerProvisioning implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; public function __construct( public Server $server, public ?Task $task = null, public ?string $errorMessage = null, ) { // } public function handle(): void { rescue(fn () => $this->task?->updateOutputWithoutCallbacks(), report: false); $this->server->createdByUser?->notify( new ServerProvisioningFailed( $this->server->name, $this->task?->tailOutput() ?: '', $this->errorMessage ?: '' ) ); $this->server->delete(); } }