Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
100 lines (72 sloc) 3.39 KB

Operation Wrappers

The purpose of this Symfony integration is to help you using operations and operation runners in an easy way. By using the AOP features provided by the JMSAopBundle you can wrap a Symfony service in an operation runner by simply using a tag or a YAML configuration.


You need to first install JMSAopBundle in order to be able to use this AOP integration.

By default this feature is not activated so you need to activate it manually:

        enabled: true

Using a tag

Let's say now that you've a service for this YourService object that contains methods that are a bit risky and needs to be wrapped into an operation runner:

namespace App;

class YourService
    public function getSomething()
        // This method needs to be in an operation runner because it's
        // doing something risky such as an API call.

Once you've that, you can use the tolerance.operation_wrapper tag to wrap the different calls to some of your service's methods inside an operation runner.

<?xml version="1.0" ?>

<container xmlns=""

        <service id="app.your_service" class="App\YourService">
            <tag name="tolerance.operation_wrapper"
                 runner="tolerance.operation_runner.default" />

The tag have 2 configuration options:

  • methods: a comma separated names of the methods you want to proxy
  • runner: the service name of the operation runner to use

And that's all, your calls to the method getSomething of your service will be wrapper inside a callback operation and run with the operation runner operation_runner.service_name.

Using YAML

You can wrap some methods of a given class into a given operation runner. The following example shows how simple it can be to simply get metrics from some API calls for instance.

All the calls to the methods requestSomething and findSomethingElse to a service with the class HttpThirdPartyClient will be proxied through the operation runner tolerance.operation_runners.3rdparty. This metrics operation runner created in YAML will record the success and failure of the operations to a metric publisher.

    enabled: true

        - class: "Acme\Your\HttpThirdPartyClient"
              - requestSomething
              - findSomethingElse
          runner: tolerance.operation_runners.3rdparty

        callback: ~

            publisher: tolerance.metrics.publisher.statsd
            namespace: 3rdparty.outgoing.requests