GithubHelp home page GithubHelp logo

eugenganshorn / guzzlebundleretryplugin Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 13.0 49 KB

Retry Plugin for EightPointsGuzzleBundle

License: MIT License

PHP 100.00%
bundle curl guzzle guzzle-bundle-plugin guzzle-middleware http http-client middleware plugin retry symfony symfony-bundle

guzzlebundleretryplugin's People

Contributors

ekosogin avatar eugenganshorn avatar mihaileu avatar sane4ek-2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

guzzlebundleretryplugin's Issues

Dependency on a non-existent logging service when EightPointsGuzzleBundle logging is disabled

There is a dependency on the eight_points_guzzle logger class. When logging is disabled on eight_points_guzzle this class is not defined by the extension.

This gives the following error;

The service "guzzle_bundle_retry_plugin.middleware.retry.xxx" has a dependency on a non-existent service "eight_points_guzzle.middleware.log.class".

Location:

public function loadForClient(array $config, ContainerBuilder $container, string $clientName, Definition $handler): void
{
    if ($config['retry_enabled']) {
        $logger = new Definition(Logger::class);
        $logger->addMethodCall('setLogger', [new Reference('monolog.logger.eight_points_guzzle')]);
        $logger->addMethodCall('setFormatter', [new Reference('eight_points_guzzle.symfony_log_formatter')]);

        $middleware = new Definition(GuzzleRetryMiddleware::class);
        $middleware->setFactory([GuzzleRetryMiddleware::class, 'factory']);
        $middleware->setArguments([
            [
                'max_retry_attempts'               => $config['max_retry_attempts'],
                'retry_only_if_retry_after_header' => $config['retry_only_if_retry_after_header'],
                'retry_on_status'                  => $config['retry_on_status'],
                'default_retry_multiplier'         => $config['default_retry_multiplier'],
                'retry_on_timeout'                 => $config['retry_on_timeout'],
                'expose_retry_header'              => $config['expose_retry_header'],
                'retry_header'                     => $config['retry_header'],
                'on_retry_callback'                => [$logger, 'callback'],
            ],
        ]);

Is it possible to use callbacks to configure 'should_retry_callback' or 'on_retry_callback'

Hi guys!
I wanted to use you plugin for retrying but I need a custom logic to decide is it need to retry a request or not.
I see that you don't use config options with callbacks, for example 'should_retry_callback' or 'on_retry_callback'
https://github.com/EugenGanshorn/GuzzleBundleRetryPlugin/blob/master/src/GuzzleBundleRetryPlugin.php#L90

I tried to make my own plugin for this but it's appeared that the logic with callbacks doesn't work because Symfony tries to serialize it here: https://github.com/symfony/dependency-injection/blob/6.3/Compiler/MergeExtensionConfigurationPass.php#L121

And finally I got error "Serialization of 'Closure' is not allowed"

My example

public function loadForClient(array $config, ContainerBuilder $container, string $clientName, Definition $handler): void
    {
        $shouldRetryCallback = function () {
            // todo
        };

        $middleware = new Definition(GuzzleRetryMiddleware::class);
        $middleware->setFactory([GuzzleRetryMiddleware::class, 'factory']);
        $middleware->setArguments([
            [
                'max_retry_attempts'               => 3,
                'retry_on_status'                  => [502, 503],
                'should_retry_callback'            => $shouldRetryCallback,
            ],
        ]);

        $middleware->setPublic(true);

        $middlewareServiceName = sprintf('guzzle_bundle_retry_plugin.middleware.retry.%s', $clientName);
        $container->setDefinition($middlewareServiceName, $middleware);

        $middlewareExpression = new Expression(sprintf('service("%s")', $middlewareServiceName));
        $handler->addMethodCall('push', [$middlewareExpression]);
    }

Sorry, it's not really issue to your plugin
But maybe you know is it possible to use callbacks to configure guzzle middlewares through plugins?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.