|
2 | 2 |
|
3 | 3 | namespace Runtime\Bref; |
4 | 4 |
|
5 | | -use Bref\Context\Context; |
6 | | -use Bref\Runtime\LambdaRuntime; |
| 5 | +use Runtime\Bref\Lambda\LambdaClient; |
7 | 6 | use Symfony\Component\Console\Application; |
8 | | -use Symfony\Component\Console\Input\ArgvInput; |
9 | | -use Symfony\Component\Console\Output\BufferedOutput; |
10 | 7 | use Symfony\Component\Runtime\RunnerInterface; |
11 | 8 |
|
12 | 9 | /** |
|
16 | 13 | */ |
17 | 14 | class ConsoleApplicationRunner implements RunnerInterface |
18 | 15 | { |
19 | | - private $application; |
| 16 | + private $handler; |
20 | 17 |
|
21 | 18 | public function __construct(Application $application) |
22 | 19 | { |
23 | | - $this->application = $application; |
24 | | - $this->application->setAutoExit(false); |
| 20 | + $this->handler = new ConsoleApplicationHandler($application); |
25 | 21 | } |
26 | 22 |
|
27 | 23 | public function run(): int |
28 | 24 | { |
29 | | - $lambda = LambdaRuntime::fromEnvironmentVariable('symfony-runtime-console'); |
| 25 | + $lambda = LambdaClient::fromEnvironmentVariable('symfony-runtime-console'); |
30 | 26 |
|
31 | 27 | while (true) { |
32 | | - $lambda->processNextEvent(function ($event, Context $context): array { |
33 | | - $args = \Clue\Arguments\split((string) $event); |
34 | | - array_unshift($args, 'command'); |
35 | | - |
36 | | - $input = new ArgvInput($args); |
37 | | - $output = new BufferedOutput(); |
38 | | - $exitCode = $this->application->run($input, $output); |
39 | | - |
40 | | - $content = $output->fetch(); |
41 | | - // Echo the output so that it is written to CloudWatch logs |
42 | | - echo $content; |
43 | | - |
44 | | - if ($exitCode > 0) { |
45 | | - throw new \Exception('The command exited with a non-zero status code: '.$exitCode); |
46 | | - } |
47 | | - |
48 | | - return [ |
49 | | - 'exitCode' => $exitCode, // will always be 0 |
50 | | - 'output' => $content, |
51 | | - ]; |
52 | | - }); |
| 28 | + $lambda->processNextEvent($this->handler); |
53 | 29 | } |
54 | 30 | } |
55 | 31 | } |
0 commit comments