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

Let LambdaRuntime::processNextEvent() return boolean #1013

Merged
merged 1 commit into from
Sep 19, 2021
Merged
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
7 changes: 6 additions & 1 deletion src/Runtime/LambdaRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ private function closeReturnHandler(): void
* $lambdaRuntime->processNextEvent(function ($event, Context $context) {
* return 'Hello ' . $event['name'] . '. We have ' . $context->getRemainingTimeInMillis()/1000 . ' seconds left';
* });
* @return bool true if event was successfully handled
* @throws Exception
*/
public function processNextEvent($handler): void
public function processNextEvent($handler): bool
{
[$event, $context] = $this->waitNextInvocation();
\assert($context instanceof Context);
Expand All @@ -104,7 +105,11 @@ public function processNextEvent($handler): void
$this->sendResponse($context->getAwsRequestId(), $result);
} catch (\Throwable $e) {
$this->signalFailure($context->getAwsRequestId(), $e);

return false;
}

return true;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions tests/Runtime/LambdaRuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ public function test basic behavior()
{
$this->givenAnEvent(['Hello' => 'world!']);

$this->runtime->processNextEvent(function () {
$output = $this->runtime->processNextEvent(function () {
return ['hello' => 'world'];
});

$this->assertTrue($output);
$this->assertInvocationResult(['hello' => 'world']);
}

Expand All @@ -73,10 +74,11 @@ public function test exceptions in the handler result in an invocation 
{
$this->givenAnEvent(['Hello' => 'world!']);

$this->runtime->processNextEvent(function () {
$output = $this->runtime->processNextEvent(function () {
throw new \RuntimeException('This is an exception');
});

$this->assertFalse($output);
$this->assertInvocationErrorResult('RuntimeException', 'This is an exception');
$this->assertErrorInLogs('RuntimeException', 'This is an exception');
}
Expand Down