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 $throttle_interval_ms = 500;
protected $throttle_interval_ms = 200;
protected int $counter = 1;
@@ -74,8 +74,14 @@ class RunRemoteProcess
$this->time_start = hrtime(true);
$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) {
$status = ProcessStatus::ERROR;
} else {
@@ -131,7 +137,6 @@ class RunRemoteProcess
}
$this->current_time = $this->elapsedTime();
$this->activity->description = $this->encodeOutput($type, $output);
if ($this->isAfterLastThrottle()) {
// Let's write to database.
DB::transaction(function () {

View File

@@ -16,6 +16,7 @@ class CoolifyTaskArgs extends Data
public string $command,
public string $type,
public ?string $type_uuid = null,
public ?int $process_id = null,
public ?Model $model = null,
public ?string $status = null ,
public bool $ignore_errors = false,

View File

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