Skip to content

Commit

Permalink
retry-after option related to fhteam#21
Browse files Browse the repository at this point in the history
increment required php version to real value
  • Loading branch information
martianoff committed Mar 30, 2018
1 parent 89d5e7f commit 20b4c96
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,44 @@ In your ```config/queue.php``` file you have to provide the following:
In your ```config/app.php``` add ```'Forumhouse\LaravelAmqp\ServiceProvider\LaravelAmqpServiceProvider'``` to the list of service
providers registered.

Improved worker stability (PHP 7.1+ is required)
------------

For better stability please add following code in app/Exceptions/Handler.php:

```php
class Handler extends ExceptionHandler
{
```

to

```php
class Handler extends ExceptionHandler
{
use AMQPFailureDetector;
```

And

```php
public function report(Exception $exception)
{
parent::report($exception);
}
```

to

```php
public function report(Exception $exception)
{
$this->catchAMQPConnectionFailure($exception);
parent::report($exception);
}
```


Usage
------------

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"minimum-stability": "stable",
"license": "GPL-2.0",
"require": {
"php": ">=7",
"php": ">=7.1",
"php-amqplib/php-amqplib": "2.6.*"
},
"require-dev": {
Expand Down
36 changes: 36 additions & 0 deletions src/Traits/AMQPFailureDetector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Forumhouse\LaravelAmqp\Traits;
use Exception;
use Illuminate\Support\Str;

trait AMQPFailureDetector
{

public function catchAMQPConnectionFailure(Exception $exception)
{
if(\App::runningInConsole() && $this->causedByLostConnection($exception) && extension_loaded('posix')){
posix_kill(getmypid(), SIGTERM);
}
}

protected function causedByLostConnection(Exception $e)
{
$message = $e->getMessage();

return Str::contains($message, [
'server has gone away',
'no connection to the server',
'Lost connection',
'is dead or not enabled',
'Error while sending',
'decryption failed or bad record mac',
'server closed the connection unexpectedly',
'SSL connection has been closed unexpectedly',
'Error writing data to the connection',
'Resource deadlock avoided',
'Transaction() on null',
'child connection forced to terminate due to client_idle_limit',
]);
}
}

0 comments on commit 20b4c96

Please sign in to comment.