fix: double ws connection

This commit is contained in:
Andras Bacsai 2023-12-08 22:51:42 +01:00
parent ba2e4c06f1
commit 6bb79e10bc
6 changed files with 53 additions and 44 deletions

View File

@ -27,7 +27,7 @@ class RunRemoteProcess
protected $last_write_at = 0; protected $last_write_at = 0;
protected $throttle_interval_ms = 500; protected $throttle_interval_ms = 200;
protected int $counter = 1; protected int $counter = 1;
@ -74,8 +74,14 @@ public function __invoke(): ProcessResult
$this->time_start = hrtime(true); $this->time_start = hrtime(true);
$status = ProcessStatus::IN_PROGRESS; $status = ProcessStatus::IN_PROGRESS;
$processResult = Process::forever()->run($this->getCommand(), $this->handleOutput(...)); $timeout = config('constants.ssh.command_timeout');
$process = Process::timeout($timeout)->start($this->getCommand(), $this->handleOutput(...));
$this->activity->properties = $this->activity->properties->merge([
'process_id' => $process->id(),
]);
$processResult = $process->wait();
// $processResult = Process::timeout($timeout)->run($this->getCommand(), $this->handleOutput(...));
if ($this->activity->properties->get('status') === ProcessStatus::ERROR->value) { if ($this->activity->properties->get('status') === ProcessStatus::ERROR->value) {
$status = ProcessStatus::ERROR; $status = ProcessStatus::ERROR;
} else { } else {
@ -131,7 +137,6 @@ protected function handleOutput(string $type, string $output)
} }
$this->current_time = $this->elapsedTime(); $this->current_time = $this->elapsedTime();
$this->activity->description = $this->encodeOutput($type, $output); $this->activity->description = $this->encodeOutput($type, $output);
if ($this->isAfterLastThrottle()) { if ($this->isAfterLastThrottle()) {
// Let's write to database. // Let's write to database.
DB::transaction(function () { DB::transaction(function () {

View File

@ -16,6 +16,7 @@ public function __construct(
public string $command, public string $command,
public string $type, public string $type,
public ?string $type_uuid = null, public ?string $type_uuid = null,
public ?int $process_id = null,
public ?Model $model = null, public ?Model $model = null,
public ?string $status = null , public ?string $status = null ,
public bool $ignore_errors = false, public bool $ignore_errors = false,

View File

@ -8,5 +8,6 @@ enum ProcessStatus: string
case IN_PROGRESS = 'in_progress'; case IN_PROGRESS = 'in_progress';
case FINISHED = 'finished'; case FINISHED = 'finished';
case ERROR = 'error'; case ERROR = 'error';
case KILLED = 'killed';
case CANCELLED = 'cancelled'; case CANCELLED = 'cancelled';
} }

View File

@ -11,4 +11,46 @@
<main class="pb-10 main max-w-screen-2xl"> <main class="pb-10 main max-w-screen-2xl">
{{ $slot }} {{ $slot }}
</main> </main>
<script data-navigate-once>
@auth
window.Pusher = Pusher;
window.Echo = new Echo({
broadcaster: 'pusher',
cluster: "{{ env('PUSHER_HOST') }}" || window.location.hostname,
key: "{{ env('PUSHER_APP_KEY') }}" || 'coolify',
wsHost: "{{ env('PUSHER_HOST') }}" || window.location.hostname,
wsPort: "{{ env('PUSHER_PORT') }}" || 6001,
wssPort: "{{ env('PUSHER_PORT') }}" || 6001,
forceTLS: false,
encrypted: true,
enableStats: false,
enableLogging: true,
enabledTransports: ['ws', 'wss'],
});
if ("{{ auth()->user()->id }}" == 0) {
let checkPusherInterval = null;
let checkNumber = 0;
let errorMessage =
"Coolify could not connect to the new realtime service introduced in beta.154.<br>Please check the related <a href='https://coolify.io/docs/cloudflare-tunnels' target='_blank'>documentation</a> or get help on <a href='https://coollabs.io/discord' target='_blank'>Discord</a>.";
checkPusherInterval = setInterval(() => {
if (window.Echo) {
if (window.Echo.connector.pusher.connection.state !== 'connected') {
checkNumber++;
if (checkNumber > 5) {
clearInterval(checkPusherInterval);
Livewire.emit('error', errorMessage);
}
} else {
console.log('Coolify is now connected to the new realtime service introduced in beta.154.');
clearInterval(checkPusherInterval);
}
} else {
clearInterval(checkPusherInterval);
Livewire.emit('error', errorMessage);
}
}, 2000);
}
@endauth
</script>
@endsection @endsection

View File

@ -46,46 +46,6 @@
<x-version class="fixed left-2 bottom-1" /> <x-version class="fixed left-2 bottom-1" />
<script data-navigate-once> <script data-navigate-once>
@auth
window.Pusher = Pusher;
window.Echo = new Echo({
broadcaster: 'pusher',
cluster: "{{ env('PUSHER_HOST') }}" || window.location.hostname,
key: "{{ env('PUSHER_APP_KEY') }}" || 'coolify',
wsHost: "{{ env('PUSHER_HOST') }}" || window.location.hostname,
wsPort: "{{ env('PUSHER_PORT') }}" || 6001,
wssPort: "{{ env('PUSHER_PORT') }}" || 6001,
forceTLS: false,
encrypted: true,
enableStats: false,
enableLogging: true,
enabledTransports: ['ws', 'wss'],
});
if ("{{ auth()->user()->id }}" == 0) {
let checkPusherInterval = null;
let checkNumber = 0;
let errorMessage =
"Coolify could not connect to the new realtime service introduced in beta.154.<br>Please check the related <a href='https://coolify.io/docs/cloudflare-tunnels' target='_blank'>documentation</a> or get help on <a href='https://coollabs.io/discord' target='_blank'>Discord</a>.";
checkPusherInterval = setInterval(() => {
if (window.Echo) {
if (window.Echo.connector.pusher.connection.state !== 'connected') {
checkNumber++;
if (checkNumber > 5) {
clearInterval(checkPusherInterval);
Livewire.emit('error', errorMessage);
}
} else {
console.log('Coolify is now connected to the new realtime service introduced in beta.154.');
clearInterval(checkPusherInterval);
}
} else {
clearInterval(checkPusherInterval);
Livewire.emit('error', errorMessage);
}
}, 2000);
}
@endauth
let checkHealthInterval = null; let checkHealthInterval = null;
let checkIfIamDeadInterval = null; let checkIfIamDeadInterval = null;

View File

@ -12,7 +12,7 @@
<div <div
class="scrollbar flex flex-col-reverse w-full overflow-y-auto border border-solid rounded border-coolgray-300 max-h-[32rem] p-4 pt-6 text-xs text-white"> class="scrollbar flex flex-col-reverse w-full overflow-y-auto border border-solid rounded border-coolgray-300 max-h-[32rem] p-4 pt-6 text-xs text-white">
<pre class="font-mono whitespace-pre-wrap" @if ($isPollingActive) wire:poll.2000ms="polling" @endif>{{ RunRemoteProcess::decodeOutput($this->activity) }}</pre> <pre class="font-mono whitespace-pre-wrap" @if ($isPollingActive) wire:poll.1000ms="polling" @endif>{{ RunRemoteProcess::decodeOutput($this->activity) }}</pre>
</div> </div>
@endif @endif
</div> </div>