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

poc: nack message on a fatal error #47

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions src/Consumers/AbstractConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private function setMessageProvider()
protected function getBaseStack()
{
$stack = (new Stack\Builder())
->push('Puzzle\AMQP\Processors\FatalErrorNack', $this->messageProvider)
->push('Swarrot\Processor\SignalHandler\SignalHandlerProcessor', $this->logger)
->push('Swarrot\Processor\ExceptionCatcher\ExceptionCatcherProcessor', $this->logger)
;
Expand Down
36 changes: 36 additions & 0 deletions src/Processors/FatalErrorNack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Puzzle\AMQP\Processors;

use Psr\Log\LoggerInterface;
use Swarrot\Broker\MessageProvider\MessageProviderInterface;
use Swarrot\Processor\ProcessorInterface;
use Swarrot\Broker\Message;

class FatalErrorNack implements ProcessorInterface
{
public function __construct(ProcessorInterface $processor, MessageProviderInterface $messageProvider)
{
$this->processor = $processor;
$this->messageProvider = $messageProvider;
}

public function process(Message $message, array $options)
{
$messageProvider = $this->messageProvider;

register_shutdown_function(function() use($messageProvider, $message) {
$error = error_get_last();

if(null !== $error)
{
if($error["type"] === E_ERROR)
{
$messageProvider->nack($message);
}
}
});

return $this->processor->process($message, $options);
}
}
10 changes: 10 additions & 0 deletions src/Processors/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Custom Swarrot Processors

**FatalErrorNack**

`FatalErrorNack` is a swarrot processor that will nack the message if a fatal run-time errors occurs (E_ERROR).

For example :
```
PHP Fatal error: Allowed memory size of XXX bytes exhausted (tried to allocate YYY bytes) in [...]
```