wip
This commit is contained in:
@@ -2,31 +2,23 @@
|
||||
|
||||
namespace App\Http\Livewire\Project\Application;
|
||||
|
||||
use App\Enums\ActivityTypes;
|
||||
use App\Models\Application;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\Models\ApplicationDeploymentQueue;
|
||||
use Livewire\Component;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
|
||||
class DeploymentLogs extends Component
|
||||
{
|
||||
public Application $application;
|
||||
public $activity;
|
||||
public ApplicationDeploymentQueue $application_deployment_queue;
|
||||
public $isKeepAliveOn = true;
|
||||
public $deployment_uuid;
|
||||
protected $listeners = ['refreshQueue'];
|
||||
public function refreshQueue()
|
||||
{
|
||||
$this->application_deployment_queue->refresh();
|
||||
}
|
||||
public function polling()
|
||||
{
|
||||
$this->emit('deploymentFinished');
|
||||
if (is_null($this->activity) && isset($this->deployment_uuid)) {
|
||||
$this->activity = Activity::query()
|
||||
->where('properties->type', '=', ActivityTypes::DEPLOYMENT->value)
|
||||
->where('properties->type_uuid', '=', $this->deployment_uuid)
|
||||
->first();
|
||||
} else {
|
||||
$this->activity?->refresh();
|
||||
}
|
||||
|
||||
if (data_get($this->activity, 'properties.status') == 'finished' || data_get($this->activity, 'properties.status') == 'failed') {
|
||||
$this->application_deployment_queue->refresh();
|
||||
if (data_get($this->application_deployment_queue, 'status') == 'finished' || data_get($this->application_deployment_queue, 'status') == 'failed') {
|
||||
$this->isKeepAliveOn = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,41 +2,46 @@
|
||||
|
||||
namespace App\Http\Livewire\Project\Application;
|
||||
|
||||
use App\Enums\ProcessStatus;
|
||||
use App\Enums\ApplicationDeploymentStatus;
|
||||
use App\Models\Application;
|
||||
use App\Models\ApplicationDeploymentQueue;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DeploymentNavbar extends Component
|
||||
{
|
||||
public Application $application;
|
||||
public $activity;
|
||||
public string $deployment_uuid;
|
||||
protected $listeners = ['deploymentFinished'];
|
||||
|
||||
public ApplicationDeploymentQueue $application_deployment_queue;
|
||||
|
||||
public function deploymentFinished()
|
||||
{
|
||||
$this->activity->refresh();
|
||||
$this->application_deployment_queue->refresh();
|
||||
}
|
||||
public function show_debug()
|
||||
{
|
||||
$application = Application::find($this->application_deployment_queue->application_id);
|
||||
$application->settings->is_debug_enabled = !$application->settings->is_debug_enabled;
|
||||
$application->settings->save();
|
||||
$this->emit('refreshQueue');
|
||||
}
|
||||
public function cancel()
|
||||
{
|
||||
try {
|
||||
ray('Cancelling deployment: ' . $this->deployment_uuid . ' of application: ' . $this->application->uuid);
|
||||
|
||||
// Update deployment queue
|
||||
$deployment = ApplicationDeploymentQueue::where('deployment_uuid', $this->deployment_uuid)->first();
|
||||
$deployment->status = 'cancelled by user';
|
||||
$deployment->save();
|
||||
|
||||
// Update activity
|
||||
$this->activity->properties = $this->activity->properties->merge([
|
||||
'exitCode' => 1,
|
||||
'status' => ProcessStatus::CANCELLED->value,
|
||||
]);
|
||||
$this->activity->save();
|
||||
|
||||
// Remove builder container
|
||||
instant_remote_process(["docker rm -f {$this->deployment_uuid}"], $this->application->destination->server, throwError: false, repeat: 25);
|
||||
queue_next_deployment($this->application);
|
||||
$application = Application::find($this->application_deployment_queue->application_id);
|
||||
$server = $application->destination->server;
|
||||
if ($this->application_deployment_queue->current_process_id) {
|
||||
$process = Process::run("ps -p {$this->application_deployment_queue->current_process_id} -o command --no-headers");
|
||||
if (Str::of($process->output())->contains([$server->ip, 'EOF-COOLIFY-SSH'])) {
|
||||
Process::run("kill -9 {$this->application_deployment_queue->current_process_id}");
|
||||
}
|
||||
// TODO: Cancelling text in logs
|
||||
$this->application_deployment_queue->update([
|
||||
'current_process_id' => null,
|
||||
'status' => ApplicationDeploymentStatus::CANCELLED_BY_USER->value,
|
||||
]);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
return general_error_handler(err: $e, that: $this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user