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.

fix: improve scheduled task adding/removing

Andras Bacsai317dc10af47f
diff --git a/app/Jobs/ScheduledTaskJob.php b/app/Jobs/ScheduledTaskJob.php
index 4a38a005b6..5c7b0d8af2 100644
--- a/app/Jobs/ScheduledTaskJob.php
+++ b/app/Jobs/ScheduledTaskJob.php
@@ -77,8 +77,12 @@ class ScheduledTaskJob implements ShouldQueue
$this->containers[] = data_get($application, 'name') . '-' . data_get($this->resource, 'uuid');
}
});
+ $this->resource->databases()->get()->each(function ($database) {
+ if (str(data_get($database, 'status'))->contains('running')) {
+ $this->containers[] = data_get($database, 'name') . '-' . data_get($this->resource, 'uuid');
+ }
+ });
}
-
if (count($this->containers) == 0) {
throw new \Exception('ScheduledTaskJob failed: No containers running.');
}
diff --git a/app/Livewire/Project/Service/Configuration.php b/app/Livewire/Project/Service/Configuration.php
index 0b26af22f3..86c9a8a319 100644
--- a/app/Livewire/Project/Service/Configuration.php
+++ b/app/Livewire/Project/Service/Configuration.php
@@ -3,7 +3,6 @@
namespace App\Livewire\Project\Service;
use App\Actions\Docker\GetContainersStatus;
-use App\Jobs\ContainerStatusJob;
use App\Models\Service;
use Livewire\Component;
diff --git a/app/Livewire/Project/Shared/ScheduledTask/Add.php b/app/Livewire/Project/Shared/ScheduledTask/Add.php
index 3a7a3fa23a..c415ff3e45 100644
--- a/app/Livewire/Project/Shared/ScheduledTask/Add.php
+++ b/app/Livewire/Project/Shared/ScheduledTask/Add.php
@@ -2,11 +2,14 @@
namespace App\Livewire\Project\Shared\ScheduledTask;
+use Illuminate\Support\Collection;
use Livewire\Component;
class Add extends Component
{
public $parameters;
+ public string $type;
+ public Collection $containerNames;
public string $name;
public string $command;
public string $frequency;
@@ -29,6 +32,9 @@ class Add extends Component
public function mount()
{
$this->parameters = get_route_parameters();
+ if ($this->containerNames->count() > 0) {
+ $this->container = $this->containerNames->first();
+ }
}
public function submit()
@@ -40,6 +46,11 @@ class Add extends Component
$this->dispatch('error', 'Invalid Cron / Human expression.');
return;
}
+ if (empty($this->container) || $this->container == 'null') {
+ if ($this->type == 'service') {
+ $this->container = $this->subServiceName;
+ }
+ }
$this->dispatch('saveScheduledTask', [
'name' => $this->name,
'command' => $this->command,
diff --git a/app/Livewire/Project/Shared/ScheduledTask/All.php b/app/Livewire/Project/Shared/ScheduledTask/All.php
index 975d695fa8..73b2733b45 100644
--- a/app/Livewire/Project/Shared/ScheduledTask/All.php
+++ b/app/Livewire/Project/Shared/ScheduledTask/All.php
@@ -3,14 +3,13 @@
namespace App\Livewire\Project\Shared\ScheduledTask;
use App\Models\ScheduledTask;
+use Illuminate\Support\Collection;
use Livewire\Component;
-use Visus\Cuid2\Cuid2;
-use Illuminate\Support\Str;
class All extends Component
{
public $resource;
- public string|null $modalId = null;
+ public Collection $containerNames;
public ?string $variables = null;
public array $parameters;
protected $listeners = ['refreshTasks', 'saveScheduledTask' => 'submit'];
@@ -18,7 +17,19 @@ class All extends Component
public function mount()
{
$this->parameters = get_route_parameters();
- $this->modalId = new Cuid2(7);
+ if ($this->resource->type() == 'service') {
+ $this->containerNames = $this->resource->applications()->pluck('name');
+ $this->containerNames = $this->containerNames->merge($this->resource->databases()->pluck('name'));
+ ray($this->containerNames);
+ } elseif ($this->resource->type() == 'application') {
+ if ($this->resource->build_pack === 'dockercompose') {
+ $parsed = $this->resource->parseCompose();
+ $containers = collect($parsed['services'])->keys();
+ $this->containerNames = $containers;
+ } else {
+ $this->containerNames = collect([]);
+ }
+ }
}
public function refreshTasks()
{
diff --git a/app/Livewire/Project/Shared/ScheduledTask/Show.php b/app/Livewire/Project/Shared/ScheduledTask/Show.php
index 87b7525092..7490c70552 100644
--- a/app/Livewire/Project/Shared/ScheduledTask/Show.php
+++ b/app/Livewire/Project/Shared/ScheduledTask/Show.php
@@ -17,6 +17,7 @@ class Show extends Component
public string $type;
protected $rules = [
+ 'task.enabled' => 'required|boolean',
'task.name' => 'required|string',
'task.command' => 'required|string',
'task.frequency' => 'required|string',
@@ -45,9 +46,18 @@ class Show extends Component
$this->task = ModelsScheduledTask::where('uuid', request()->route('task_uuid'))->first();
}
+ public function instantSave()
+ {
+ $this->validateOnly('task.enabled');
+ $this->task->save(['enabled' => $this->task->enabled]);
+ $this->dispatch('success', 'Scheduled task updated.');
+ $this->dispatch('refreshTasks');
+ }
public function submit()
{
$this->validate();
+ $this->task->name = str($this->task->name)->trim()->value();
+ $this->task->container = str($this->task->container)->trim()->value();
$this->task->save();
$this->dispatch('success', 'Scheduled task updated.');
$this->dispatch('refreshTasks');
@@ -60,11 +70,9 @@ class Show extends Component
if ($this->type == 'application') {
return redirect()->route('project.application.configuration', $this->parameters);
- }
- else {
+ } else {
return redirect()->route('project.service.configuration', $this->parameters);
}
-
} catch (\Exception $e) {
return handleError($e);
}
diff --git a/app/Models/Service.php b/app/Models/Service.php
index cd8e578d61..770dfae2e9 100644
--- a/app/Models/Service.php
+++ b/app/Models/Service.php
@@ -677,6 +677,17 @@ class Service extends BaseModel
{
return $this->belongsTo(Server::class);
}
+ public function byUuid(string $uuid) {
+ $app = $this->applications()->whereUuid($uuid)->first();
+ if ($app) {
+ return $app;
+ }
+ $db = $this->databases()->whereUuid($uuid)->first();
+ if ($db) {
+ return $db;
+ }
+ return null;
+ }
public function byName(string $name)
{
$app = $this->applications()->whereName($name)->first();
diff --git a/resources/views/livewire/project/service/configuration.blade.php b/resources/views/livewire/project/service/configuration.blade.php
index 16cabf6894..185fbdb77e 100644
--- a/resources/views/livewire/project/service/configuration.blade.php
+++ b/resources/views/livewire/project/service/configuration.blade.php
@@ -16,6 +16,10 @@
@click.prevent="activeTab = 'storages';
window.location.hash = 'storages'"
href="#">Storages</a>
+ <a class="menu-item" :class="activeTab === 'scheduled-tasks' && 'menu-item-active'"
+ @click.prevent="activeTab = 'scheduled-tasks'; window.location.hash = 'scheduled-tasks'"
+ href="#">Scheduled Tasks
+ </a>
<a class="menu-item sm:min-w-fit" :class="activeTab === 'execute-command' && 'menu-item-active'"
@click.prevent="activeTab = 'execute-command';
window.location.hash = 'execute-command'"
@@ -103,10 +107,13 @@
href="{{ route('project.service.index', [...$parameters, 'stack_service_uuid' => $application->uuid]) }}">
Settings
</a>
- <x-modal-confirmation action="restartApplication({{ $application->id }})"
- isErrorButton buttonTitle="Restart">
- This application will be unavailable during the restart. <br>Please think again.
- </x-modal-confirmation>
+ @if (str($application->status)->contains('running'))
+ <x-modal-confirmation action="restartApplication({{ $application->id }})"
+ isErrorButton buttonTitle="Restart">
+ This application will be unavailable during the restart. <br>Please think
+ again.
+ </x-modal-confirmation>
+ @endif
</div>
</div>
</div>
@@ -169,6 +176,9 @@
<livewire:project.service.storage wire:key="database-{{ $database->id }}" :resource="$database" />
@endforeach
</div>
+ <div x-cloak x-show="activeTab === 'scheduled-tasks'">
+ <livewire:project.shared.scheduled-task.all :resource="$service" />
+ </div>
<div x-cloak x-show="activeTab === 'webhooks'">
<livewire:project.shared.webhooks :resource="$service" />
</div>
diff --git a/resources/views/livewire/project/service/index.blade.php b/resources/views/livewire/project/service/index.blade.php
index 318df88d03..0ce919049d 100644
--- a/resources/views/livewire/project/service/index.blade.php
+++ b/resources/views/livewire/project/service/index.blade.php
@@ -10,14 +10,6 @@
<a class="menu-item" :class="activeTab === 'general' && 'menu-item-active'"
@click.prevent="activeTab = 'general'; window.location.hash = 'general'; if(window.location.search) window.location.search = ''"
href="#">General</a>
- <a class="menu-item" :class="activeTab === 'storages' && 'menu-item-active'"
- @click.prevent="activeTab = 'storages'; window.location.hash = 'storages'; if(window.location.search) window.location.search = ''"
- href="#">Storages
- </a>
- <a class="menu-item" :class="activeTab === 'scheduled-tasks' && 'menu-item-active'"
- @click.prevent="activeTab = 'scheduled-tasks'; window.location.hash = 'scheduled-tasks'"
- href="#">Scheduled Tasks
- </a>
@if (str($serviceDatabase?->databaseType())->contains('mysql') ||
str($serviceDatabase?->databaseType())->contains('postgres') ||
str($serviceDatabase?->databaseType())->contains('mariadb'))
@@ -30,28 +22,12 @@
<div x-cloak x-show="activeTab === 'general'" class="h-full">
<livewire:project.service.service-application-view :application="$serviceApplication" />
</div>
- <div x-cloak x-show="activeTab === 'storages'">
- <div class="flex items-center gap-2">
- <h2>Storages</h2>
- </div>
- <div class="pb-4">Persistent storage to preserve data between deployments.</div>
- <span class="dark:text-warning">Please modify storage layout in your Docker Compose file.</span>
- <livewire:project.service.storage wire:key="application-{{ $serviceApplication->id }}"
- :resource="$serviceApplication" />
- </div>
+
@endisset
@isset($serviceDatabase)
<div x-cloak x-show="activeTab === 'general'" class="h-full">
<livewire:project.service.database :database="$serviceDatabase" />
</div>
- <div x-cloak x-show="activeTab === 'storages'">
- <div class="flex items-center gap-2">
- <h2>Storages</h2>
- </div>
- <div class="pb-4">Persistent storage to preserve data between deployments.</div>
- <span class="dark:text-warning">Please modify storage layout in your Docker Compose file.</span>
- <livewire:project.service.storage wire:key="application-{{ $serviceDatabase->id }}" :resource="$serviceDatabase" />
- </div>
<div x-cloak x-show="activeTab === 'backups'">
<div class="flex gap-2 ">
<h2 class="pb-4">Scheduled Backups</h2>
@@ -62,9 +38,6 @@
<livewire:project.database.scheduled-backups :database="$serviceDatabase" />
</div>
@endisset
- <div x-cloak x-show="activeTab === 'scheduled-tasks'">
- <livewire:project.shared.scheduled-task.all :resource="$service" />
- </div>
</div>
</div>
</div>
diff --git a/resources/views/livewire/project/shared/scheduled-task/add.blade.php b/resources/views/livewire/project/shared/scheduled-task/add.blade.php
index 3226981b8a..9e9af07bf4 100644
--- a/resources/views/livewire/project/shared/scheduled-task/add.blade.php
+++ b/resources/views/livewire/project/shared/scheduled-task/add.blade.php
@@ -1,10 +1,27 @@
<form class="flex flex-col w-full gap-2 rounded" wire:submit='submit'>
- <x-forms.input autofocus placeholder="Run cron" id="name" label="Name" />
- <x-forms.input placeholder="php artisan schedule:run" id="command" label="Command" />
- <x-forms.input placeholder="0 0 * * * or daily" id="frequency" label="Frequency" />
- <x-forms.input placeholder="php" id="container"
- helper="You can leave it empty if your resource only have one container." label="Container name" />
- <x-forms.button @click="slideOverOpen=false" type="submit">
+ <x-forms.input autofocus placeholder="Run cron" id="name" label="Name" />
+ <x-forms.input placeholder="php artisan schedule:run" id="command" label="Command" />
+ <x-forms.input placeholder="0 0 * * * or daily" id="frequency" label="Frequency" />
+ @if ($type === 'application')
+ @if ($containerNames->count() > 1)
+ <x-forms.select id="container" label="Container name">
+ @foreach ($containerNames as $containerName)
+ <option value="{{ $containerName }}">{{ $containerName }}</option>
+ @endforeach
+ </x-forms.select>
+ @else
+ <x-forms.input placeholder="php" id="container"
+ helper="You can leave it empty if your resource only have one container." label="Container name" />
+ @endif
+ @elseif ($type === 'service')
+ <x-forms.select id="container" label="Container name">
+ @foreach ($containerNames as $containerName)
+ <option value="{{ $containerName }}">{{ $containerName }}</option>
+ @endforeach
+ </x-forms.select>
+ @endif
+
+ <x-forms.button @click="modalOpen=false" type="submit">
Save
</x-forms.button>
</form>
diff --git a/resources/views/livewire/project/shared/scheduled-task/all.blade.php b/resources/views/livewire/project/shared/scheduled-task/all.blade.php
index 3ed22e5e7b..a3c0587ca4 100644
--- a/resources/views/livewire/project/shared/scheduled-task/all.blade.php
+++ b/resources/views/livewire/project/shared/scheduled-task/all.blade.php
@@ -1,8 +1,12 @@
<div>
<div class="flex gap-2">
<h2>Scheduled Tasks</h2>
- <x-modal-input buttonTitle="+ Add" title="New Scheduled Task">
- <livewire:project.shared.scheduled-task.add />
+ <x-modal-input buttonTitle="+ Add" title="New Scheduled Task" :closeOutside=false>
+ @if ($resource->type() == 'application')
+ <livewire:project.shared.scheduled-task.add :type="$resource->type()" :containerNames="$containerNames"/>
+ @elseif ($resource->type() == 'service')
+ <livewire:project.shared.scheduled-task.add :type="$resource->type()" :containerNames="$containerNames"/>
+ @endif
</x-modal-input>
</div>
<div class="flex flex-wrap gap-2 pt-4">
@@ -11,7 +15,12 @@
<a class="box"
href="{{ route('project.application.scheduled-tasks', [...$parameters, 'task_uuid' => $task->uuid]) }}">
<span class="flex flex-col">
- <span class="font-bold">{{ $task->name }}</span>
+ <span class="text-lg font-bold">{{ $task->name }}
+ @if ($task->container)
+ <span class="text-xs font-normal">({{ $task->container }})</span>
+ @endif
+ </span>
+
<span>Frequency: {{ $task->frequency }}</span>
<span>Last run: {{ data_get($task->latest_log, 'status', 'No runs yet') }}
</span>
@@ -21,7 +30,11 @@
<a class="box"
href="{{ route('project.service.scheduled-tasks', [...$parameters, 'task_uuid' => $task->uuid]) }}">
<span class="flex flex-col">
- <span class="font-bold">{{ $task->name }}</span>
+ <span class="text-lg font-bold">{{ $task->name }}
+ @if ($task->container)
+ <span class="text-xs font-normal">({{ $task->container }})</span>
+ @endif
+ </span>
<span>Frequency: {{ $task->frequency }}</span>
<span>Last run: {{ data_get($task->latest_log, 'status', 'No runs yet') }}
</span>
diff --git a/resources/views/livewire/project/shared/scheduled-task/executions.blade.php b/resources/views/livewire/project/shared/scheduled-task/executions.blade.php
index 4daa4933ae..afbf1ea939 100644
--- a/resources/views/livewire/project/shared/scheduled-task/executions.blade.php
+++ b/resources/views/livewire/project/shared/scheduled-task/executions.blade.php
@@ -12,7 +12,7 @@
</div>
@endif
<a wire:click="selectTask({{ data_get($execution, 'id') }})" @class([
- 'flex flex-col border-l border-dashed transition-colors box-without-bg bg-coolgray-100 hover:bg-coolgray-100 cursor-pointer',
+ 'flex flex-col border-l transition-colors box-without-bg bg-coolgray-100 hover:bg-coolgray-200 cursor-pointer',
'bg-coolgray-200 dark:text-white hover:bg-coolgray-200' =>
data_get($execution, 'id') == $selectedKey,
'border-green-500' => data_get($execution, 'status') === 'success',
diff --git a/resources/views/livewire/project/shared/scheduled-task/show.blade.php b/resources/views/livewire/project/shared/scheduled-task/show.blade.php
index 144d22f165..9a08fe04bb 100644
--- a/resources/views/livewire/project/shared/scheduled-task/show.blade.php
+++ b/resources/views/livewire/project/shared/scheduled-task/show.blade.php
@@ -1,13 +1,13 @@
<div>
- <h1>Scheduled Task</h1>
@if ($type === 'application')
+ <h1>Scheduled Task</h1>
<livewire:project.application.heading :application="$resource" />
@elseif ($type === 'service')
<livewire:project.service.navbar :service="$resource" :parameters="$parameters" />
@endif
<form wire:submit="submit" class="w-full">
- <div class="flex flex-col gap-2 pb-4">
+ <div class="flex flex-col gap-2 pb-2">
<div class="flex items-end gap-2 pt-4">
<h2>Scheduled Task</h2>
<x-forms.button type="submit">
@@ -17,13 +17,23 @@
You will delete scheduled task <span class="font-bold dark:text-warning">{{ $task->name }}</span>.
</x-modal-confirmation>
</div>
+ <div class="w-48">
+ <x-forms.checkbox instantSave id="task.enabled" label="Enabled" />
+ </div>
</div>
<div class="flex w-full gap-2">
<x-forms.input placeholder="Name" id="task.name" label="Name" required />
<x-forms.input placeholder="php artisan schedule:run" id="task.command" label="Command" required />
<x-forms.input placeholder="0 0 * * * or daily" id="task.frequency" label="Frequency" required />
- <x-forms.input placeholder="php" helper="You can leave it empty if your resource only have one container."
- id="task.container" label="Container name" />
+ @if ($type === 'application')
+ <x-forms.input placeholder="php"
+ helper="You can leave it empty if your resource only have one container." id="task.container"
+ label="Container name" />
+ @elseif ($type === 'service')
+ <x-forms.input placeholder="php"
+ helper="You can leave it empty if your resource only have one service in your stack. Otherwise use the stack name, without the random generated id. So if you have a mysql service in your stack, use mysql."
+ id="task.container" label="Service name" />
+ @endif
</div>
</form>