Skip to content

Allow laravel to end workers with lost connection #457

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

Merged
merged 1 commit into from
Apr 6, 2022
Merged
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
13 changes: 13 additions & 0 deletions src/Queue/RabbitMQQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
use JsonException;
use PhpAmqpLib\Channel\AMQPChannel;
use PhpAmqpLib\Connection\AbstractConnection;
use PhpAmqpLib\Exception\AMQPChannelClosedException;
use PhpAmqpLib\Exception\AMQPConnectionClosedException;
use PhpAmqpLib\Exception\AMQPProtocolChannelException;
use PhpAmqpLib\Exception\AMQPRuntimeException;
use PhpAmqpLib\Exchange\AMQPExchangeType;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPTable;
Expand Down Expand Up @@ -254,6 +257,16 @@ public function pop($queue = null)
}

throw $exception;
} catch (AMQPChannelClosedException|AMQPConnectionClosedException $exception) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

// Queue::pop used by worker to receive new job
// Thrown exception is checked by Illuminate\Database\DetectsLostConnections::causedByLostConnection
// Is has to contain one of the several phrases in exception message in order to restart worker
// Otherwise worker continues to work with broken connection
throw new AMQPRuntimeException(
'Lost connection: '.$exception->getMessage(),
$exception->getCode(),
$exception
);
}

return null;
Expand Down