Giter VIP home page Giter VIP logo

periodic-batching's Introduction

Build Status Quality Gate Status

NuGet Downloads NuGet Version

Periodic Batching

Execute a batching function with a controlled size every some specified time interval. Very useful for background processes to send events to some broker or something like it.

Sample

// some class 
public class MyEvent
{
    public string SomeProperty { get; set; }
}

// method that will be called every X seconds/minutes/etc
public static async Task ExecuteMethod(List<MyEvent> events)
{
    // do something
}

// configuring periodic batching
var config = new PeriodicBatchingConfiguration<MyEvent>
{
    BatchSizeLimit = 5,                               // list size for when BatchingFunc method is called. default 50.
    FailuresBeforeDroppingBatch = 3,                  // after X consecutive failures, current batch will be dropped. Use -1 to cancel this behavior. default 5.
    FailuresBeforeDroppingQueue = 10,                 // after X consecutive failures, all queue items will be dropped. Use -1 to cancel this behavior. deafult 10.
    BatchingFunc = ExecuteMethod,                     // (required) delegate called to process batch
    SingleFailureCallback = SingleFailure,            // (optional) delegate called when a single failure happens - exception, failures count and queue count are passed as parameter.
    DropBatchCallback = DropBatch,                    // (optional) delegate called when a batch is dropped - current batch items are passed as parameter.
    DropQueueCallback = DropQueue,                    // (optional) delegate called when a queue is dropped - all queue items are passed as parameter.
    Period = TimeSpan.FromSeconds(5),                 // interval to execute main method - BatchingFunc. default 10s.
    MinimumBackoffPeriod = TimeSpan.FromSeconds(3),   // interval used for next inteval when a failure happens. for each error, interval is increased exponentially based on this value. default 3s.
    MaximumBackoffInterval = TimeSpan.FromMinutes(5), // max interval. this parameter will limit the exponential interval. default 5m.
};

IPeriodicBatching<MyEvent> periodicBatching = new PeriodicBatching<MyEvent>(config);

// or 

IPeriodicBatching<MyEvent> periodicBatchingOtherWay = new PeriodicBatching<MyEvent>();
periodicBatchingOtherWay.Setup(config);

// sample of other delegates

public static async Task SingleFailure(Exception e, int failures, int queueCount))
{
    // do something
}

public static async Task DropBatch(List<SomeEvent> events)
{
    // do something
}

public static async Task DropQueue(List<SomeEvent> events)
{
    // do something
}

Install via NuGet

PM> Install-Package PeriodicBatching

How can I contribute?

Please, refer to CONTRIBUTING

Found something strange or need a new feature?

Open a new Issue following our issue template ISSUE_TEMPLATE

Did you like it? Please, make a donate :)

if you liked this project, please make a contribution and help to keep this and other initiatives, send me some Satochis.

BTC Wallet: 1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX

1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX

periodic-batching's People

Contributors

thiagobarradas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.