Skip to content

Commit

Permalink
[1.x] Adds --timeout option (#45)
Browse files Browse the repository at this point in the history
* Adds `--timeout` option

* Adjusts

* stlye
  • Loading branch information
nunomaduro authored Oct 21, 2024
1 parent 8530355 commit 085a230
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Console/Commands/PailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class PailCommand extends Command
{--message= : Filter the logs by the given message}
{--level= : Filter the logs by the given level}
{--auth= : Filter the logs by the given authenticated ID}
{--user= : Filter the logs by the given authenticated ID (alias for --auth)}';
{--user= : Filter the logs by the given authenticated ID (alias for --auth)}
{--timeout=3600 : The maximum execution time in seconds}';

/**
* {@inheritDoc}
Expand Down
13 changes: 12 additions & 1 deletion src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Options
* Creates a new instance of the tail options.
*/
public function __construct(
protected int $timeout,
protected ?string $authId,
protected ?string $level,
protected ?string $filter,
Expand All @@ -36,7 +37,9 @@ public static function fromCommand(Command $command): static
$message = $command->option('message');
assert(is_string($message) || $message === null);

return new static($authId, $level, $filter, $message);
$timeout = (int) $command->option('timeout');

return new static($timeout, $authId, $level, $filter, $message);
}

/**
Expand All @@ -62,4 +65,12 @@ public function accepts(MessageLogged $messageLogged): bool

return true;
}

/**
* Returns the number of seconds before the process is killed.
*/
public function timeout(): int
{
return $this->timeout;
}
}
2 changes: 1 addition & 1 deletion src/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function run(File $file, OutputInterface $output, string $basePath, Optio

$remainingBuffer = '';

Process::timeout(3600)
Process::timeout($options->timeout())
->tty(false)
->run(
$this->command($file),
Expand Down

0 comments on commit 085a230

Please sign in to comment.