Giter VIP home page Giter VIP logo

cracker's Introduction

Cracker

I saw some Polly code in an application and wondered why it was so complex... I deliberately didnt look at the Polly source code as it would throw my implementation.

I had previously written my own throttle and retry code for Xero so I thought I would try rolling my own version with Timeout for fun.

Example:

var result = await new CrackerBuilder()
    .Throttle(callLimit: 100, period: TimeSpan.FromSeconds(60))
    .Timeout(TimeSpan.FromSeconds(1))
    .Retry(retryAttempts: 3)
    .WithDelayBetweenRetries(attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)))
    .UnessException<CustomException>()
    .UnessException<HttpException>(x => x.ErrorCode = 404)
    .ExecuteAsync(job.ExecuteAsync);

TODO:

  • Timeout applies to the entire call stack, it should only apply for the calls after it on the bulder. e.g.
// Timeout after 1 second, attempt up to 3 times, .
var result = await new CrackerBuilder()
    .Timeout(TimeSpan.FromSeconds(1))
    .Retry(retryAttempts: 3)
    .ExecuteAsync(job.ExecuteAsync);

// vrs
// Attempt 3 times, timeout after 1 second on each try.
var result = await new CrackerBuilder()
    .Retry(retryAttempts: 3)
    .Timeout(TimeSpan.FromSeconds(1))
    .ExecuteAsync(job.ExecuteAsync);

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.