8p / EightPointsGuzzleBundle

⛽️ Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony
MIT License
440 stars 71 forks source link

[Plugin] Retry functionality #176

Closed gregurco closed 5 years ago

gregurco commented 6 years ago

Create plugin with retry functionality. Middleware repository: https://packagist.org/packages/caseyamcl/guzzle_retry_middleware

EugenGanshorn commented 5 years ago

is there somewhere a documentation how to create plugins?

gregurco commented 5 years ago

Hello @EugenGanshorn You can read this example to see how to create single-file plugin: https://github.com/8p/EightPointsGuzzleBundle/blob/master/src/Resources/doc/how-to-create-a-single-file-plugin.md also you can follow the example of other plugins: https://github.com/8p/EightPointsGuzzleBundle#known-and-supported-plugins

As a middleware you can use this package: https://packagist.org/packages/caseyamcl/guzzle_retry_middleware

EugenGanshorn commented 5 years ago

okay. i am created a plugin and it works, but one question: how can i use the logger in my plugin? i tried to do it like: $logger = new Definition(Logger::class); $logger->addMethodCall('setLogger', [new Reference('eight_points_guzzle.logger')]); and inside my "Logger" class: $this->logger->error($this->formatter->format($request, $response), ['request' => $request, 'response' => $response]); but messages which i try to log are just not logged. why?

gregurco commented 5 years ago

Because you're using guzzle logger. Use logger from Symfony: Psr\Log\LoggerInterface. Link: https://symfony.com/doc/current/logging.html#logging-a-message

EugenGanshorn commented 5 years ago

yes, with the symfony logger it works. but for example the 8p guzzle bundle logger has following output: [2019-06-05 20:33:01] eight_points_guzzle.INFO: GET https://httpstat.us/503 503 [] [] and the symfony logger: [2019-06-05 20:52:11] app.ERROR: ... and i just want to have the same output to be consistent. and in my opinion it should be possible to disable the logging with the bundle config ("logging: false")

EugenGanshorn commented 5 years ago

okay, i guess the trick is: $logger->addMethodCall('setLogger', [new Reference('monolog.logger.eight_points_guzzle')]);

EugenGanshorn commented 5 years ago

could you pls review my plugin? https://github.com/EugenGanshorn/GuzzleBundleRetryPlugin

gregurco commented 5 years ago

Hello @EugenGanshorn Sorry for delay and thank you for your effort to create new plugin. Generally it's great, but I have one suggestion: it's not a good practice to keep composer.lock in repository.

EugenGanshorn commented 5 years ago

You're right, I removed it.

Maybe you could close this issue then, if there is nothing else to do?

gregurco commented 5 years ago

Yes, I close it. Thank you :+1: You can open PR to add your plugin to this list: https://github.com/8p/EightPointsGuzzleBundle#known-and-supported-plugins