From 9ede07dd15bc4edbf8a707f1490b19ec02b276d6 Mon Sep 17 00:00:00 2001 From: bangnokia Date: Wed, 26 Jun 2024 03:23:05 +0700 Subject: [PATCH 1/5] add correctly Type for $runner in PhpStorm --- src/TaskDispatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TaskDispatcher.php b/src/TaskDispatcher.php index 2858654..16eac4f 100644 --- a/src/TaskDispatcher.php +++ b/src/TaskDispatcher.php @@ -80,7 +80,7 @@ private function runInBackground(PendingTask $pendingTask) */ private function runOnConnection(PendingTask $pendingTask): ProcessOutput { - /** @var RemoteProcessRunner */ + /** @var RemoteProcessRunner $runner */ $runner = app()->makeWith( RemoteProcessRunner::class, ['connection' => $pendingTask->getConnection(), 'processRunner' => $this->processRunner] From 76335247e75a8b762369b07c9dfc397ff45d7b5b Mon Sep 17 00:00:00 2001 From: bangnokia Date: Wed, 26 Jun 2024 03:33:25 +0700 Subject: [PATCH 2/5] make the upload timeout configurable --- config/task-runner.php | 3 +++ src/RemoteProcessRunner.php | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config/task-runner.php b/config/task-runner.php index dce6a31..c3e9d56 100644 --- a/config/task-runner.php +++ b/config/task-runner.php @@ -31,4 +31,7 @@ 'enabled' => env('TASK_RUNNER_PERSISTENT_FAKE', false), 'storage_root' => storage_path('framework/testing/task-runner'), ], + + // The default timeout for uploading script file to server in seconds + 'upload_timeout' => 10, ]; diff --git a/src/RemoteProcessRunner.php b/src/RemoteProcessRunner.php index 9b50166..fd256ed 100644 --- a/src/RemoteProcessRunner.php +++ b/src/RemoteProcessRunner.php @@ -141,6 +141,7 @@ private function cleanupOutput(ProcessOutput $processOutput): ProcessOutput * * @param string $filename * @param string $contents + * @param int $timeout */ public function upload($filename, $contents): self { @@ -156,7 +157,7 @@ public function upload($filename, $contents): self ]); $output = $this->processRunner->run( - FacadesProcess::command($command)->timeout(10) + FacadesProcess::command($command)->timeout(config('task-runner.upload_timeout')) ); if ($output->isTimeout() || $output->getExitCode() !== 0) { From a3e9b019dddeeb1def874842f5f4b13bca456401 Mon Sep 17 00:00:00 2001 From: bangnokia Date: Wed, 26 Jun 2024 03:36:23 +0700 Subject: [PATCH 3/5] make fallback for default value --- src/RemoteProcessRunner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RemoteProcessRunner.php b/src/RemoteProcessRunner.php index fd256ed..f677d15 100644 --- a/src/RemoteProcessRunner.php +++ b/src/RemoteProcessRunner.php @@ -157,7 +157,7 @@ public function upload($filename, $contents): self ]); $output = $this->processRunner->run( - FacadesProcess::command($command)->timeout(config('task-runner.upload_timeout')) + FacadesProcess::command($command)->timeout(config('task-runner.upload_timeout', 10)) ); if ($output->isTimeout() || $output->getExitCode() !== 0) { From ec57334cc7fa18e7c8af2ddcca21a68454e0deac Mon Sep 17 00:00:00 2001 From: bangnokia Date: Sat, 29 Jun 2024 01:50:37 +0700 Subject: [PATCH 4/5] rename to connection_timeout --- config/task-runner.php | 4 ++-- src/RemoteProcessRunner.php | 9 +++++---- src/TaskDispatcher.php | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/config/task-runner.php b/config/task-runner.php index c3e9d56..9e6ccf9 100644 --- a/config/task-runner.php +++ b/config/task-runner.php @@ -32,6 +32,6 @@ 'storage_root' => storage_path('framework/testing/task-runner'), ], - // The default timeout for uploading script file to server in seconds - 'upload_timeout' => 10, + // The connection timeout for connecting to a remote server in seconds. + 'connection_timeout' => 10, ]; diff --git a/src/RemoteProcessRunner.php b/src/RemoteProcessRunner.php index f677d15..7dd5064 100644 --- a/src/RemoteProcessRunner.php +++ b/src/RemoteProcessRunner.php @@ -14,7 +14,8 @@ class RemoteProcessRunner public function __construct( private Connection $connection, - private ProcessRunner $processRunner + private ProcessRunner $processRunner, + private int $connectionTimeout = 10, ) { } @@ -46,7 +47,7 @@ public function verifyScriptDirectoryExists(): self { $output = $this->run( script: 'mkdir -p '.$this->connection->scriptPath, - timeout: 10 + timeout: $this->connectionTimeout, ); if ($output->isTimeout() || $output->getExitCode() !== 0) { @@ -96,7 +97,7 @@ public function runUploadedScriptInBackground(string $script, string $output, in timeout: $timeout, ); - return $this->run($script, 10); + return $this->run($script, $this->connectionTimeout); } /** @@ -157,7 +158,7 @@ public function upload($filename, $contents): self ]); $output = $this->processRunner->run( - FacadesProcess::command($command)->timeout(config('task-runner.upload_timeout', 10)) + FacadesProcess::command($command)->timeout(config('task-runner.connection_timeout', 10)) ); if ($output->isTimeout() || $output->getExitCode() !== 0) { diff --git a/src/TaskDispatcher.php b/src/TaskDispatcher.php index 16eac4f..fd38ae0 100644 --- a/src/TaskDispatcher.php +++ b/src/TaskDispatcher.php @@ -60,7 +60,7 @@ public function run(PendingTask $pendingTask): ?ProcessOutput /** * Runs the given task in the background. * - * @return void + * @return ProcessOutput */ private function runInBackground(PendingTask $pendingTask) { @@ -71,7 +71,7 @@ private function runInBackground(PendingTask $pendingTask) ); return $this->processRunner->run( - FacadesProcess::command($command)->timeout(10) + FacadesProcess::command($command)->timeout(config('task-runner.connection_timeout', 10)) ); } @@ -83,7 +83,7 @@ private function runOnConnection(PendingTask $pendingTask): ProcessOutput /** @var RemoteProcessRunner $runner */ $runner = app()->makeWith( RemoteProcessRunner::class, - ['connection' => $pendingTask->getConnection(), 'processRunner' => $this->processRunner] + ['connection' => $pendingTask->getConnection(), 'processRunner' => $this->processRunner, 'connectionTimeout' => config('task-runner.connection_timeout', 10)] ); if ($outputCallbable = $pendingTask->getOnOutput()) { From 16c6ec431fdbd38baecfb5f4a179de842b03ba3c Mon Sep 17 00:00:00 2001 From: bangnokia Date: Sat, 29 Jun 2024 02:04:02 +0700 Subject: [PATCH 5/5] remove config --- src/RemoteProcessRunner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RemoteProcessRunner.php b/src/RemoteProcessRunner.php index 7dd5064..6699348 100644 --- a/src/RemoteProcessRunner.php +++ b/src/RemoteProcessRunner.php @@ -158,7 +158,7 @@ public function upload($filename, $contents): self ]); $output = $this->processRunner->run( - FacadesProcess::command($command)->timeout(config('task-runner.connection_timeout', 10)) + FacadesProcess::command($command)->timeout($this->connectionTimeout) ); if ($output->isTimeout() || $output->getExitCode() !== 0) {