An open API service indexing awesome lists of open source software.

https://github.com/thiagobarradas/periodic-batching

Library with generic periodic batching for dotnet applications.
https://github.com/thiagobarradas/periodic-batching

batch batch-job batch-processing batch-script batching dotnet dotnet-core dotnet-framework dotnet-standard dotnet5 dotnetcore3 periodic-batching

Last synced: 12 months ago
JSON representation

Library with generic periodic batching for dotnet applications.

Awesome Lists containing this project

README

          

[![Build Status](https://barradas.visualstudio.com/Contributions/_apis/build/status/NugetPackage/Periodic%20Batching?branchName=develop)](https://barradas.visualstudio.com/Contributions/_build/latest?definitionId=26&branchName=develop)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ThiagoBarradas_periodic-batching&metric=alert_status)](https://sonarcloud.io/dashboard?id=ThiagoBarradas_periodic-batching)

[![NuGet Downloads](https://img.shields.io/nuget/dt/PeriodicBatching.svg)](https://www.nuget.org/packages/PeriodicBatching/)
[![NuGet Version](https://img.shields.io/nuget/v/PeriodicBatching.svg)](https://www.nuget.org/packages/PeriodicBatching/)

# 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

```c#

// 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 events)
{
// do something
}

// configuring periodic batching
var config = new PeriodicBatchingConfiguration
{
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 periodicBatching = new PeriodicBatching(config);

// or

IPeriodicBatching periodicBatchingOtherWay = new PeriodicBatching();
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 events)
{
// do something
}

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

```

## Install via NuGet

```
PM> Install-Package PeriodicBatching
```

## How can I contribute?

Please, refer to [CONTRIBUTING](.github/CONTRIBUTING.md)

## Found something strange or need a new feature?

Open a new Issue following our issue template [ISSUE_TEMPLATE](.github/ISSUE_TEMPLATE.md)

## 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](https://i.imgur.com/mN7ueoE.png)