2023-08-07 16:46:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Project\Database;
|
|
|
|
|
|
|
|
use App\Actions\Database\StartPostgresql;
|
2023-09-14 10:45:50 +00:00
|
|
|
use App\Jobs\ContainerStatusJob;
|
2023-08-08 09:51:36 +00:00
|
|
|
use Livewire\Component;
|
2023-08-07 16:46:40 +00:00
|
|
|
|
|
|
|
class Heading extends Component
|
|
|
|
{
|
|
|
|
public $database;
|
|
|
|
public array $parameters;
|
|
|
|
|
2023-08-07 20:14:21 +00:00
|
|
|
protected $listeners = ['activityFinished'];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function activityFinished()
|
|
|
|
{
|
2023-08-07 20:14:21 +00:00
|
|
|
$this->database->update([
|
|
|
|
'started_at' => now(),
|
|
|
|
]);
|
|
|
|
$this->emit('refresh');
|
|
|
|
$this->check_status();
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-08-07 20:14:21 +00:00
|
|
|
public function check_status()
|
|
|
|
{
|
2023-09-14 10:45:50 +00:00
|
|
|
dispatch_sync(new ContainerStatusJob($this->database->destination->server));
|
2023-08-07 20:14:21 +00:00
|
|
|
$this->database->refresh();
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-08-07 16:46:40 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-08-09 13:57:53 +00:00
|
|
|
$this->parameters = get_route_parameters();
|
2023-08-07 16:46:40 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function stop()
|
|
|
|
{
|
2023-09-15 13:34:25 +00:00
|
|
|
instant_remote_process(
|
2023-08-07 20:14:21 +00:00
|
|
|
["docker rm -f {$this->database->uuid}"],
|
|
|
|
$this->database->destination->server
|
|
|
|
);
|
2023-09-07 11:23:34 +00:00
|
|
|
if ($this->database->is_public) {
|
|
|
|
stopPostgresProxy($this->database);
|
|
|
|
$this->database->is_public = false;
|
|
|
|
}
|
2023-09-18 10:38:11 +00:00
|
|
|
$this->database->status = 'exited';
|
2023-08-07 20:14:21 +00:00
|
|
|
$this->database->save();
|
2023-09-15 13:34:25 +00:00
|
|
|
$this->check_status();
|
2023-08-27 12:53:16 +00:00
|
|
|
// $this->database->environment->project->team->notify(new StatusChanged($this->database));
|
2023-08-07 20:14:21 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function start()
|
|
|
|
{
|
2023-08-07 20:14:21 +00:00
|
|
|
if ($this->database->type() === 'standalone-postgresql') {
|
2023-08-07 16:46:40 +00:00
|
|
|
$activity = resolve(StartPostgresql::class)($this->database->destination->server, $this->database);
|
|
|
|
$this->emit('newMonitorActivity', $activity->id);
|
|
|
|
}
|
|
|
|
}
|
2023-08-07 20:14:21 +00:00
|
|
|
}
|