2024-01-01 18:33:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Livewire\Project\Shared\ScheduledTask;
|
|
|
|
|
|
|
|
use App\Models\ScheduledTask;
|
|
|
|
use Livewire\Component;
|
|
|
|
use Visus\Cuid2\Cuid2;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
class All extends Component
|
|
|
|
{
|
|
|
|
public $resource;
|
|
|
|
public string|null $modalId = null;
|
|
|
|
public ?string $variables = null;
|
2024-01-02 02:23:29 +00:00
|
|
|
public array $parameters;
|
2024-01-01 18:33:16 +00:00
|
|
|
protected $listeners = ['refreshTasks', 'saveScheduledTask' => 'submit'];
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2024-01-02 02:23:29 +00:00
|
|
|
$this->parameters = get_route_parameters();
|
2024-01-01 18:33:16 +00:00
|
|
|
$this->modalId = new Cuid2(7);
|
|
|
|
}
|
|
|
|
public function refreshTasks()
|
|
|
|
{
|
|
|
|
$this->resource->refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function submit($data)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$task = new ScheduledTask();
|
|
|
|
$task->name = $data['name'];
|
|
|
|
$task->command = $data['command'];
|
|
|
|
$task->frequency = $data['frequency'];
|
|
|
|
$task->container = $data['container'];
|
2024-01-05 05:06:36 +00:00
|
|
|
$task->team_id = currentTeam()->id;
|
2024-01-01 18:33:16 +00:00
|
|
|
|
|
|
|
switch ($this->resource->type()) {
|
|
|
|
case 'application':
|
|
|
|
$task->application_id = $this->resource->id;
|
|
|
|
break;
|
|
|
|
case 'standalone-postgresql':
|
|
|
|
$task->standalone_postgresql_id = $this->resource->id;
|
|
|
|
break;
|
|
|
|
case 'service':
|
|
|
|
$task->service_id = $this->resource->id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$task->save();
|
|
|
|
$this->refreshTasks();
|
2024-02-22 13:53:42 +00:00
|
|
|
$this->dispatch('success', 'Scheduled task added.');
|
2024-01-01 18:33:16 +00:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|