Download the PHP package tebru/executioner without Composer
On this page you can find all versions of the php package tebru/executioner. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tebru/executioner
More information about tebru/executioner
Files in tebru/executioner
Package executioner
Short Description Provides a library for handling PHP exceptions when you would like to retry execution.
License MIT
Informations about the package executioner
Executioner
This library aims to create an easy way to execute code that may throw an exception and should be reattempted.
Installation
Run composer require tebru/executioner:dev-master
Basic Usage
The library can be used as simply as this
Which will retry twice on all exceptions. Failure to execute without throwing an exception will cause a \Tebru\Executioner\Exception\FailedException
to be thrown. Be sure to wrap your execute()
call in a try/catch if you do not want that exception to propagate.
Events
Events are used to provides hooks/insight into the operations. The 4 events are:
- beforeAttempt
- afterAttempt
- failedAttempt
- endAttempt
This library uses the Symfony2 event dispatcher. Feel free to use the included subscribers or create your own.
Use the listener methods on the Executor to target one event, and use subscribers to target multiple events.
Delay between attempts
There are two wait strategies included:
- Tebru\Executioner\Strategy\StaticWaitStrategy -- Waits for a set amount of time between each attempt
- Tebru\Executioner\Strategy\ExponentialBackoffStrategy -- On average, exponentially waits longer between each attempt
Logging
Retry on non-exceptions
Shortcuts
To make life easier, there are some helper methods to create some of the included subscribers
Add a LoggerSubscriber
Add a WaitSubscriber using the StaticWaitStrategy
Add a WaitSubscriber