diff --git a/README.md b/README.md index 909b5da..8ad2cdc 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,11 @@ $app->register(new RabbitServiceProvider(), [ 'connection' => 'default', 'exchange_options' => ['name' => 'a_exchange','type' => 'topic'], 'queue_options' => ['name' => 'a_queue', 'routing_keys' => ['foo.#']], - 'callback' => 'your_consumer_service' + 'callback' => 'your_consumer_service', + 'graceful_max_execution' => [ + 'timeout' => 900, + 'exit_code' => 10, + ], ] ] ]); diff --git a/src/fiunchinho/Silex/Provider/RabbitServiceProvider.php b/src/fiunchinho/Silex/Provider/RabbitServiceProvider.php index 2667c4f..757afc6 100644 --- a/src/fiunchinho/Silex/Provider/RabbitServiceProvider.php +++ b/src/fiunchinho/Silex/Provider/RabbitServiceProvider.php @@ -165,6 +165,16 @@ private function loadConsumers(Container $container) $consumer->disableAutoSetupFabric(); } + if (array_key_exists('graceful_max_execution', $options)) { + $grace = $options['graceful_max_execution']; + if (array_key_exists('timeout', $grace)) { + $consumer->setGracefulMaxExecutionDateTimeFromSecondsInTheFuture($grace['timeout']); + } + if (array_key_exists('exit_code', $grace)) { + $consumer->setGracefulMaxExecutionTimeoutExitCode($grace['exit_code']); + } + } + $consumers[$name] = $consumer; }