formatting

This commit is contained in:
ayntk-ai
2024-08-16 21:22:06 +02:00
parent 80b90b3a2c
commit 48734e53d0
4 changed files with 95 additions and 93 deletions

View File

@@ -55,10 +55,13 @@ class ScheduledTaskJob implements ShouldQueue
private function getServerTimezone(): string private function getServerTimezone(): string
{ {
if ($this->resource instanceof Application) { if ($this->resource instanceof Application) {
return $this->resource->destination->server->settings->server_timezone; $timezone = $this->resource->destination->server->settings->server_timezone;
return $timezone;
} elseif ($this->resource instanceof Service) { } elseif ($this->resource instanceof Service) {
return $this->resource->server->settings->server_timezone; $timezone = $this->resource->server->settings->server_timezone;
return $timezone;
} }
return 'UTC';
} }
public function middleware(): array public function middleware(): array
@@ -91,12 +94,12 @@ class ScheduledTaskJob implements ShouldQueue
} elseif ($this->resource->type() == 'service') { } elseif ($this->resource->type() == 'service') {
$this->resource->applications()->get()->each(function ($application) { $this->resource->applications()->get()->each(function ($application) {
if (str(data_get($application, 'status'))->contains('running')) { if (str(data_get($application, 'status'))->contains('running')) {
$this->containers[] = data_get($application, 'name').'-'.data_get($this->resource, 'uuid'); $this->containers[] = data_get($application, 'name') . '-' . data_get($this->resource, 'uuid');
} }
}); });
$this->resource->databases()->get()->each(function ($database) { $this->resource->databases()->get()->each(function ($database) {
if (str(data_get($database, 'status'))->contains('running')) { if (str(data_get($database, 'status'))->contains('running')) {
$this->containers[] = data_get($database, 'name').'-'.data_get($this->resource, 'uuid'); $this->containers[] = data_get($database, 'name') . '-' . data_get($this->resource, 'uuid');
} }
}); });
} }
@@ -109,8 +112,8 @@ class ScheduledTaskJob implements ShouldQueue
} }
foreach ($this->containers as $containerName) { foreach ($this->containers as $containerName) {
if (count($this->containers) == 1 || str_starts_with($containerName, $this->task->container.'-'.$this->resource->uuid)) { if (count($this->containers) == 1 || str_starts_with($containerName, $this->task->container . '-' . $this->resource->uuid)) {
$cmd = "sh -c '".str_replace("'", "'\''", $this->task->command)."'"; $cmd = "sh -c '" . str_replace("'", "'\''", $this->task->command) . "'";
$exec = "docker exec {$containerName} {$cmd}"; $exec = "docker exec {$containerName} {$cmd}";
$this->task_output = instant_remote_process([$exec], $this->server, true); $this->task_output = instant_remote_process([$exec], $this->server, true);
$this->task_log->update([ $this->task_log->update([
@@ -135,7 +138,6 @@ class ScheduledTaskJob implements ShouldQueue
// send_internal_notification('ScheduledTaskJob failed with: ' . $e->getMessage()); // send_internal_notification('ScheduledTaskJob failed with: ' . $e->getMessage());
throw $e; throw $e;
} finally { } finally {
} }
} }
} }

View File

@@ -38,7 +38,8 @@ class ScheduledTask extends BaseModel
$server = $this->application->server; $server = $this->application->server;
ray('Returning server from application: '.$server); ray('Returning server from application: '.$server);
return $server; return $server;
} elseif ($this->database) { }
elseif ($this->database) {
ray('Returning server from database'); ray('Returning server from database');
$server = $this->database->server; $server = $this->database->server;
ray('Returning server from database: '.$server); ray('Returning server from database: '.$server);

View File

@@ -1,57 +1,56 @@
<div wire:init='refreshBackupExecutions'> <div wire:init='refreshBackupExecutions'>
@isset($backup) @isset($backup)
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<h3 class="py-4">Executions</h3> <h3 class="py-4">Executions</h3>
<x-forms.button wire:click='cleanupFailed'>Cleanup Failed Backups</x-forms.button> <x-forms.button wire:click='cleanupFailed'>Cleanup Failed Backups</x-forms.button>
</div> </div>
<div class="flex flex-col-reverse gap-2"> <div class="flex flex-col-reverse gap-2">
@forelse($executions as $execution) @forelse($executions as $execution)
<form wire:key="{{ data_get($execution, 'id') }}" <form wire:key="{{ data_get($execution, 'id') }}"
class="relative flex flex-col p-4 bg-white box-without-bg dark:bg-coolgray-100" class="relative flex flex-col p-4 bg-white box-without-bg dark:bg-coolgray-100"
@class([ @class([ 'border-green-500'=> data_get($execution, 'status') === 'success',
'border-green-500' => data_get($execution, 'status') === 'success', 'border-red-500' => data_get($execution, 'status') === 'failed',
'border-red-500' => data_get($execution, 'status') === 'failed', ])>
])> @if (data_get($execution, 'status') === 'running')
@if (data_get($execution, 'status') === 'running') <div class="absolute top-2 right-2">
<div class="absolute top-2 right-2"> <x-loading />
<x-loading /> </div>
</div> @endif
@endif <div>Database: {{ data_get($execution, 'database_name', 'N/A') }}</div>
<div>Database: {{ data_get($execution, 'database_name', 'N/A') }}</div> <div>Status: {{ data_get($execution, 'status') }}</div>
<div>Status: {{ data_get($execution, 'status') }}</div> <div>Started At: {{ $this->formatDateInServerTimezone(data_get($execution, 'created_at')) }}</div>
<div>Started At: {{ $this->formatDateInServerTimezone(data_get($execution, 'created_at')) }}</div> @if (data_get($execution, 'message'))
@if (data_get($execution, 'message')) <div>Message: {{ data_get($execution, 'message') }}</div>
<div>Message: {{ data_get($execution, 'message') }}</div> @endif
@endif <div>Size: {{ data_get($execution, 'size') }} B /
<div>Size: {{ data_get($execution, 'size') }} B / {{ round((int) data_get($execution, 'size') / 1024, 2) }}
{{ round((int) data_get($execution, 'size') / 1024, 2) }} kB / {{ round((int) data_get($execution, 'size') / 1024 / 1024, 3) }} MB
kB / {{ round((int) data_get($execution, 'size') / 1024 / 1024, 3) }} MB </div>
</div> <div>Location: {{ data_get($execution, 'filename', 'N/A') }}</div>
<div>Location: {{ data_get($execution, 'filename', 'N/A') }}</div> <div class="flex gap-2">
<div class="flex gap-2"> <div class="flex-1"></div>
<div class="flex-1"></div> @if (data_get($execution, 'status') === 'success')
@if (data_get($execution, 'status') === 'success') <x-forms.button class=" dark:hover:bg-coolgray-400"
<x-forms.button class=" dark:hover:bg-coolgray-400" x-on:click="download_file('{{ data_get($execution, 'id') }}')">Download</x-forms.button>
x-on:click="download_file('{{ data_get($execution, 'id') }}')">Download</x-forms.button> @endif
@endif <x-modal-confirmation isErrorButton action="deleteBackup({{ data_get($execution, 'id') }})">
<x-modal-confirmation isErrorButton action="deleteBackup({{ data_get($execution, 'id') }})"> <x-slot:button-title>
<x-slot:button-title> Delete
Delete </x-slot:button-title>
</x-slot:button-title> This will delete this backup. It is not reversible.<br>Please think again.
This will delete this backup. It is not reversible.<br>Please think again. </x-modal-confirmation>
</x-modal-confirmation> </div>
</div> </form>
</form>
@empty @empty
<div>No executions found.</div> <div>No executions found.</div>
@endforelse @endforelse
</div> </div>
<script> <script>
function download_file(executionId) { function download_file(executionId) {
window.open('/download/backup/' + executionId, '_blank'); window.open('/download/backup/' + executionId, '_blank');
} }
</script> </script>
@endisset @endisset
</div> </div>

View File

@@ -1,47 +1,47 @@
<div> <div>
<x-slot:title> <x-slot:title>
{{ data_get_str($resource, 'name')->limit(10) }} > Scheduled Tasks | Coolify {{ data_get_str($resource, 'name')->limit(10) }} > Scheduled Tasks | Coolify
</x-slot> </x-slot>
@if ($type === 'application') @if ($type === 'application')
<h1>Scheduled Task</h1> <h1>Scheduled Task</h1>
<livewire:project.application.heading :application="$resource" /> <livewire:project.application.heading :application="$resource" />
@elseif ($type === 'service') @elseif ($type === 'service')
<livewire:project.service.navbar :service="$resource" :parameters="$parameters" /> <livewire:project.service.navbar :service="$resource" :parameters="$parameters" />
@endif @endif
<form wire:submit="submit" class="w-full"> <form wire:submit="submit" class="w-full">
<div class="flex flex-col gap-2 pb-2"> <div class="flex flex-col gap-2 pb-2">
<div class="flex items-end gap-2 pt-4"> <div class="flex items-end gap-2 pt-4">
<h2>Scheduled Task</h2> <h2>Scheduled Task</h2>
<x-forms.button type="submit"> <x-forms.button type="submit">
Save Save
</x-forms.button> </x-forms.button>
<x-modal-confirmation isErrorButton buttonTitle="Delete Scheduled Task"> <x-modal-confirmation isErrorButton buttonTitle="Delete Scheduled Task">
You will delete scheduled task <span class="font-bold dark:text-warning">{{ $task->name }}</span>. You will delete scheduled task <span class="font-bold dark:text-warning">{{ $task->name }}</span>.
</x-modal-confirmation> </x-modal-confirmation>
</div>
<div class="w-48">
<x-forms.checkbox instantSave id="task.enabled" label="Enabled" />
</div>
</div> </div>
<div class="w-48"> <div class="flex w-full gap-2">
<x-forms.checkbox instantSave id="task.enabled" label="Enabled" /> <x-forms.input placeholder="Name" id="task.name" label="Name" required />
</div> <x-forms.input placeholder="php artisan schedule:run" id="task.command" label="Command" required />
</div> <x-forms.input placeholder="0 0 * * * or daily" id="task.frequency" label="Frequency" required />
<div class="flex w-full gap-2"> @if ($type === 'application')
<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 />
@if ($type === 'application')
<x-forms.input placeholder="php" <x-forms.input placeholder="php"
helper="You can leave it empty if your resource only have one container." id="task.container" helper="You can leave it empty if your resource only have one container." id="task.container"
label="Container name" /> label="Container name" />
@elseif ($type === 'service') @elseif ($type === 'service')
<x-forms.input placeholder="php" <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." 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" /> id="task.container" label="Service name" />
@endif @endif
</div> </div>
</form> </form>
<div class="pt-4"> <div class="pt-4">
<h3 class="py-4">Recent executions <span class="text-xs text-neutral-500">(click to check output)</span></h3> <h3 class="py-4">Recent executions <span class="text-xs text-neutral-500">(click to check output)</span></h3>
<livewire:project.shared.scheduled-task.executions :task="$task" key="{{ $task->id }}" selectedKey="" :executions="$task->executions->take(-20)" /> <livewire:project.shared.scheduled-task.executions :task="$task" key="{{ $task->id }}" selectedKey="" :executions="$task->executions->take(-20)" />
</div> </div>
</div> </div>