项目作者: iwillspeak

项目描述 :
🐦⏳ - Execution statistics for Polly policies
高级语言: C#
项目地址: git://github.com/iwillspeak/PollyTick.git
创建时间: 2017-02-28T20:21:34Z
项目社区:https://github.com/iwillspeak/PollyTick

开源协议:MIT License

下载


🐦⏳ PollyTick ⏳🐦

Execution statistics for Polly policies.

This library is aims to provide a simple wrapper for the wonderful Polly 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.

  1. var stats = Ticker
  2. .WithPolicy(Policy.NoOp())
  3. .Execute(() => 1701);
  4. Assert.Equal(1, stats.Executions);
  5. 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.

  1. var overall = new BookkeepingObserver();
  2. var ticker = Ticker
  3. .WithPolicy(Policy.NoOp())
  4. .WithObserver(overall);
  5. var one = new BookkeepingObserver();
  6. ticker.Execute(() => 1000, one);
  7. ticker.Execute(() => { throw new Exception(); });
  8. Assert.Equal(2, overall.Executions);
  9. Assert.Equal(1, overall.Exceptions);
  10. Assert.Equal(1, one.Executions);
  11. Assert.Equal(0, one.Exceptions);

Naturally there’s async support too:

  1. var stats = await Ticker
  2. .WithPolicy(Policy.NoOpAsync())
  3. .ExecuteAsync(() => Task.Delay(100));
  4. Assert.True(stats.Elapsed >= TimeSpan.FromMilliseconds(100));

Installation

You can get your hands on PollyTick from Nuget.

  1. PM> Install-Package PollyTick

or for .NET Core update project.json

  1. "PollyTick": "0.4.0",