Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the upload timeout for a script configurable #14

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/task-runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
'enabled' => env('TASK_RUNNER_PERSISTENT_FAKE', false),
'storage_root' => storage_path('framework/testing/task-runner'),
],

// The connection timeout for connecting to a remote server in seconds.
'connection_timeout' => 10,
];
10 changes: 6 additions & 4 deletions src/RemoteProcessRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class RemoteProcessRunner

public function __construct(
private Connection $connection,
private ProcessRunner $processRunner
private ProcessRunner $processRunner,
private int $connectionTimeout = 10,
) {
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -141,6 +142,7 @@ private function cleanupOutput(ProcessOutput $processOutput): ProcessOutput
*
* @param string $filename
* @param string $contents
* @param int $timeout
*/
public function upload($filename, $contents): self
{
Expand All @@ -156,7 +158,7 @@ public function upload($filename, $contents): self
]);

$output = $this->processRunner->run(
FacadesProcess::command($command)->timeout(10)
FacadesProcess::command($command)->timeout($this->connectionTimeout)
);

if ($output->isTimeout() || $output->getExitCode() !== 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/TaskDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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))
);
}

Expand All @@ -80,10 +80,10 @@ 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]
['connection' => $pendingTask->getConnection(), 'processRunner' => $this->processRunner, 'connectionTimeout' => config('task-runner.connection_timeout', 10)]
);

if ($outputCallbable = $pendingTask->getOnOutput()) {
Expand Down