Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

refactor(notifications): build scheduled task links from the instance url

peaklabs-dev85ec70643f4a
diff --git a/app/Models/Application.php b/app/Models/Application.php
index f8eb75a5ab..6bfbb6de75 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -621,32 +621,6 @@ class Application extends BaseModel
&& $this->restart_limit_reached === true;
}
- public function taskLink($task_uuid)
- {
- if (data_get($this, 'environment.project.uuid')) {
- $route = route('project.application.scheduled-tasks', [
- 'project_uuid' => data_get($this, 'environment.project.uuid'),
- 'environment_uuid' => data_get($this, 'environment.uuid'),
- 'application_uuid' => data_get($this, 'uuid'),
- 'task_uuid' => $task_uuid,
- ]);
- $settings = instanceSettings();
- if (data_get($settings, 'fqdn')) {
- $url = Url::fromString($route);
- $url = $url->withPort(null);
- $fqdn = data_get($settings, 'fqdn');
- $fqdn = str_replace(['http://', 'https://'], '', $fqdn);
- $url = $url->withHost($fqdn);
-
- return $url->__toString();
- }
-
- return $route;
- }
-
- return null;
- }
-
public function settings()
{
return $this->hasOne(ApplicationSetting::class);
diff --git a/app/Models/Service.php b/app/Models/Service.php
index 66c67ca8de..1e6a33ad69 100644
--- a/app/Models/Service.php
+++ b/app/Models/Service.php
@@ -15,7 +15,6 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use OpenApi\Attributes as OA;
use Spatie\Activitylog\Models\Activity;
-use Spatie\Url\Url;
use Symfony\Component\Yaml\Yaml;
#[OA\Schema(
@@ -1463,32 +1462,6 @@ class Service extends BaseModel
return null;
}
- public function taskLink($task_uuid)
- {
- if (data_get($this, 'environment.project.uuid')) {
- $route = route('project.service.scheduled-tasks', [
- 'project_uuid' => data_get($this, 'environment.project.uuid'),
- 'environment_uuid' => data_get($this, 'environment.uuid'),
- 'service_uuid' => data_get($this, 'uuid'),
- 'task_uuid' => $task_uuid,
- ]);
- $settings = InstanceSettings::get();
- if (data_get($settings, 'fqdn')) {
- $url = Url::fromString($route);
- $url = $url->withPort(null);
- $fqdn = data_get($settings, 'fqdn');
- $fqdn = str_replace(['http://', 'https://'], '', $fqdn);
- $url = $url->withHost($fqdn);
-
- return $url->__toString();
- }
-
- return $route;
- }
-
- return null;
- }
-
public function documentation()
{
$services = get_service_templates();
diff --git a/app/Notifications/ScheduledTask/TaskFailed.php b/app/Notifications/ScheduledTask/TaskFailed.php
index bd060112ae..2ca3874ba0 100644
--- a/app/Notifications/ScheduledTask/TaskFailed.php
+++ b/app/Notifications/ScheduledTask/TaskFailed.php
@@ -2,6 +2,7 @@
namespace App\Notifications\ScheduledTask;
+use App\Models\Application;
use App\Models\ScheduledTask;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
@@ -16,10 +17,10 @@ class TaskFailed extends CustomEmailNotification
public function __construct(public ScheduledTask $task, public string $output)
{
$this->onQueue('high');
- if ($task->application) {
- $this->url = $task->application->taskLink($task->uuid);
- } elseif ($task->service) {
- $this->url = $task->service->taskLink($task->uuid);
+ $resource = $task->application ?? $task->service;
+ if ($resource) {
+ $type = $resource instanceof Application ? 'application' : 'service';
+ $this->url = base_url().'/project/'.data_get($resource, 'environment.project.uuid').'/environment/'.data_get($resource, 'environment.uuid')."/{$type}/{$resource->uuid}/tasks/{$task->uuid}";
}
}
diff --git a/app/Notifications/ScheduledTask/TaskSuccess.php b/app/Notifications/ScheduledTask/TaskSuccess.php
index 58c959bd8d..2978eaed32 100644
--- a/app/Notifications/ScheduledTask/TaskSuccess.php
+++ b/app/Notifications/ScheduledTask/TaskSuccess.php
@@ -2,6 +2,7 @@
namespace App\Notifications\ScheduledTask;
+use App\Models\Application;
use App\Models\ScheduledTask;
use App\Notifications\CustomEmailNotification;
use App\Notifications\Dto\DiscordMessage;
@@ -16,10 +17,10 @@ class TaskSuccess extends CustomEmailNotification
public function __construct(public ScheduledTask $task, public string $output)
{
$this->onQueue('high');
- if ($task->application) {
- $this->url = $task->application->taskLink($task->uuid);
- } elseif ($task->service) {
- $this->url = $task->service->taskLink($task->uuid);
+ $resource = $task->application ?? $task->service;
+ if ($resource) {
+ $type = $resource instanceof Application ? 'application' : 'service';
+ $this->url = base_url().'/project/'.data_get($resource, 'environment.project.uuid').'/environment/'.data_get($resource, 'environment.uuid')."/{$type}/{$resource->uuid}/tasks/{$task->uuid}";
}
}