diff --git a/app/Jobs/ScheduledTaskJob.php b/app/Jobs/ScheduledTaskJob.php
index 4a38a005b..5c7b0d8af 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 0b26af22f..86c9a8a31 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 3a7a3fa23..c415ff3e4 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 975d695fa..73b2733b4 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 87b752509..7490c7055 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 cd8e578d6..770dfae2e 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 16cabf689..185fbdb77 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
+ Scheduled Tasks
+
Settings
-
Please think again.
-
Please think
+ again.
+