@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Livewire\Project\Shared\ScheduledTask;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Collection;
|
||||
use Livewire\Component;
|
||||
|
||||
@@ -54,10 +53,12 @@ class Add extends Component
|
||||
if (! $isValid) {
|
||||
$this->dispatch('error', 'Invalid Cron / Human expression.');
|
||||
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
if (($this->container === null || $this->container === '' || $this->container === '0' || $this->container === 'null') && $this->type === 'service') {
|
||||
$this->container = $this->subServiceName;
|
||||
if (empty($this->container) || $this->container === 'null') {
|
||||
if ($this->type === 'service') {
|
||||
$this->container = $this->subServiceName;
|
||||
}
|
||||
}
|
||||
$this->dispatch('saveScheduledTask', [
|
||||
'name' => $this->name,
|
||||
@@ -66,11 +67,9 @@ class Add extends Component
|
||||
'container' => $this->container,
|
||||
]);
|
||||
$this->clear();
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function clear()
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Livewire\Project\Shared\ScheduledTask;
|
||||
use App\Models\ScheduledTask;
|
||||
use Illuminate\Support\Collection;
|
||||
use Livewire\Component;
|
||||
use Throwable;
|
||||
|
||||
class All extends Component
|
||||
{
|
||||
@@ -44,31 +43,29 @@ class All extends Component
|
||||
public function submit($data)
|
||||
{
|
||||
try {
|
||||
$scheduledTask = new ScheduledTask;
|
||||
$scheduledTask->name = $data['name'];
|
||||
$scheduledTask->command = $data['command'];
|
||||
$scheduledTask->frequency = $data['frequency'];
|
||||
$scheduledTask->container = $data['container'];
|
||||
$scheduledTask->team_id = currentTeam()->id;
|
||||
$task = new ScheduledTask;
|
||||
$task->name = $data['name'];
|
||||
$task->command = $data['command'];
|
||||
$task->frequency = $data['frequency'];
|
||||
$task->container = $data['container'];
|
||||
$task->team_id = currentTeam()->id;
|
||||
|
||||
switch ($this->resource->type()) {
|
||||
case 'application':
|
||||
$scheduledTask->application_id = $this->resource->id;
|
||||
$task->application_id = $this->resource->id;
|
||||
break;
|
||||
case 'standalone-postgresql':
|
||||
$scheduledTask->standalone_postgresql_id = $this->resource->id;
|
||||
$task->standalone_postgresql_id = $this->resource->id;
|
||||
break;
|
||||
case 'service':
|
||||
$scheduledTask->service_id = $this->resource->id;
|
||||
$task->service_id = $this->resource->id;
|
||||
break;
|
||||
}
|
||||
$scheduledTask->save();
|
||||
$task->save();
|
||||
$this->refreshTasks();
|
||||
$this->dispatch('success', 'Scheduled task added.');
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
namespace App\Livewire\Project\Shared\ScheduledTask;
|
||||
|
||||
use App\Models\ScheduledTask;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\Locked;
|
||||
@@ -31,7 +28,7 @@ class Executions extends Component
|
||||
|
||||
public $logsPerPage = 100;
|
||||
|
||||
public $selectedExecution;
|
||||
public $selectedExecution = null;
|
||||
|
||||
public $isPollingActive = false;
|
||||
|
||||
@@ -48,7 +45,7 @@ class Executions extends Component
|
||||
{
|
||||
try {
|
||||
$this->taskId = $taskId;
|
||||
$this->task = ScheduledTask::query()->findOrFail($taskId);
|
||||
$this->task = ScheduledTask::findOrFail($taskId);
|
||||
$this->executions = $this->task->executions()->take(20)->get();
|
||||
$this->serverTimezone = data_get($this->task, 'application.destination.server.settings.server_timezone');
|
||||
if (! $this->serverTimezone) {
|
||||
@@ -57,11 +54,9 @@ class Executions extends Component
|
||||
if (! $this->serverTimezone) {
|
||||
$this->serverTimezone = 'UTC';
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
return handleError($e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function refreshExecutions(): void
|
||||
@@ -129,7 +124,7 @@ class Executions extends Component
|
||||
{
|
||||
$execution = $this->executions->firstWhere('id', $executionId);
|
||||
if (! $execution) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
return response()->streamDownload(function () use ($execution) {
|
||||
@@ -150,11 +145,11 @@ class Executions extends Component
|
||||
public function formatDateInServerTimezone($date)
|
||||
{
|
||||
$serverTimezone = $this->serverTimezone;
|
||||
$dateObj = new DateTime($date);
|
||||
$dateObj = new \DateTime($date);
|
||||
try {
|
||||
$dateObj->setTimezone(new DateTimeZone($serverTimezone));
|
||||
} catch (Exception) {
|
||||
$dateObj->setTimezone(new DateTimeZone('UTC'));
|
||||
$dateObj->setTimezone(new \DateTimeZone($serverTimezone));
|
||||
} catch (\Exception) {
|
||||
$dateObj->setTimezone(new \DateTimeZone('UTC'));
|
||||
}
|
||||
|
||||
return $dateObj->format('Y-m-d H:i:s T');
|
||||
|
||||
@@ -6,7 +6,6 @@ use App\Jobs\ScheduledTaskJob;
|
||||
use App\Models\Application;
|
||||
use App\Models\ScheduledTask;
|
||||
use App\Models\Service;
|
||||
use Exception;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
@@ -69,11 +68,9 @@ class Show extends Component
|
||||
|
||||
$this->task = $this->resource->scheduled_tasks()->where('uuid', $task_uuid)->firstOrFail();
|
||||
$this->syncData();
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
return handleError($e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function syncData(bool $toModel = false)
|
||||
@@ -101,11 +98,9 @@ class Show extends Component
|
||||
$this->syncData(true);
|
||||
$this->dispatch('success', 'Scheduled task updated.');
|
||||
$this->refreshTasks();
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
return handleError($e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function submit()
|
||||
@@ -113,22 +108,18 @@ class Show extends Component
|
||||
try {
|
||||
$this->syncData(true);
|
||||
$this->dispatch('success', 'Scheduled task updated.');
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
return handleError($e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function refreshTasks()
|
||||
{
|
||||
try {
|
||||
$this->task->refresh();
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
return handleError($e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
@@ -138,10 +129,10 @@ class Show extends Component
|
||||
|
||||
if ($this->type === 'application') {
|
||||
return redirect()->route('project.application.configuration', $this->parameters, $this->task->name);
|
||||
} else {
|
||||
return redirect()->route('project.service.configuration', $this->parameters, $this->task->name);
|
||||
}
|
||||
|
||||
return redirect()->route('project.service.configuration', $this->parameters, $this->task->name);
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
return handleError($e);
|
||||
}
|
||||
}
|
||||
@@ -151,10 +142,8 @@ class Show extends Component
|
||||
try {
|
||||
ScheduledTaskJob::dispatch($this->task);
|
||||
$this->dispatch('success', 'Scheduled task executed.');
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
return handleError($e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user