Skip to content

Commit

Permalink
Add support for LoopMax for ConsoleApplicationRunner (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm authored Nov 22, 2023
1 parent 78fe628 commit e738c3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/ConsoleApplicationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@
class ConsoleApplicationRunner implements RunnerInterface
{
private $handler;
private $loopMax;

public function __construct(Application $application)
public function __construct(Application $application, int $loopMax = 1)
{
$this->handler = new ConsoleApplicationHandler($application);
$this->loopMax = $loopMax;
}

public function run(): int
{
$lambda = LambdaClient::fromEnvironmentVariable('symfony-runtime-console');

$loops = 0;
while (true) {
if (++$loops > $this->loopMax) {
return 0;
}

/*
* In case the execution failed, we force starting a new process. This
* is because an uncaught exception could have left the application
Expand Down
2 changes: 1 addition & 1 deletion src/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private function tryToFindRunner(?object $application)
}

if ($application instanceof Application) {
return new ConsoleApplicationRunner($application);
return new ConsoleApplicationRunner($application, $this->options['bref_loop_max']);
}

return parent::getRunner($application);
Expand Down

0 comments on commit e738c3a

Please sign in to comment.