https://github.com/iwillspeak/pollytick
🐦⏳ - Execution statistics for Polly policies
https://github.com/iwillspeak/pollytick
execution-statistics hacktoberfest polly-policies poly
Last synced: about 1 month ago
JSON representation
🐦⏳ - Execution statistics for Polly policies
- Host: GitHub
- URL: https://github.com/iwillspeak/pollytick
- Owner: iwillspeak
- License: mit
- Created: 2017-02-28T20:21:34.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2022-09-03T15:02:54.000Z (over 2 years ago)
- Last Synced: 2025-04-10T00:04:59.981Z (about 1 month ago)
- Topics: execution-statistics, hacktoberfest, polly-policies, poly
- Language: C#
- Homepage:
- Size: 64.5 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🐦⏳ PollyTick ⏳🐦
Execution statistics for Polly policies.
This library is aims to provide a simple wrapper for the wonderful [Polly](http://thepollyproject.org/) to collect statistics about policy executions. It aims to allow programmers keep track of what policies are costing them time, and provide a seam to observe policy executions.
## Features
* Keep track of `Policy` execution time
* Allow `async` policy execution
* Supports policies with results
* Can capture exceptions, or allow them to trickle up the stack
* Collected statistics available through fine-grained observers## Example
PollyTick provides a fluent interface for observing the execution of Polly policies.
```C#
var stats = Ticker
.WithPolicy(Policy.NoOp())
.Execute(() => 1701);
Assert.Equal(1, stats.Executions);
Assert.Equal(1701, stats.Result);
```Statistics aren't just returned from each execution. An observer can be registered when preparing the `Ticker`, and passed in to each `Execute` call.
```C#
var overall = new BookkeepingObserver();
var ticker = Ticker
.WithPolicy(Policy.NoOp())
.WithObserver(overall);var one = new BookkeepingObserver();
ticker.Execute(() => 1000, one);
ticker.Execute(() => { throw new Exception(); });Assert.Equal(2, overall.Executions);
Assert.Equal(1, overall.Exceptions);Assert.Equal(1, one.Executions);
Assert.Equal(0, one.Exceptions);
```Naturally there's `async` support too:
```C#
var stats = await Ticker
.WithPolicy(Policy.NoOpAsync())
.ExecuteAsync(() => Task.Delay(100));
Assert.True(stats.Elapsed >= TimeSpan.FromMilliseconds(100));
```## Installation
You can get your hands on `PollyTick` from Nuget.
PM> Install-Package PollyTick
or for .NET Core update `project.json`
"PollyTick": "0.4.0",