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.
- Host: GitHub
- URL: https://github.com/thiagobarradas/periodic-batching
- Owner: ThiagoBarradas
- License: mit
- Created: 2021-02-04T02:50:45.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-14T20:57:20.000Z (about 5 years ago)
- Last Synced: 2025-04-07T08:46:16.233Z (about 1 year ago)
- Topics: batch, batch-job, batch-processing, batch-script, batching, dotnet, dotnet-core, dotnet-framework, dotnet-standard, dotnet5, dotnetcore3, periodic-batching
- Language: C#
- Homepage: https://www.nuget.org/packages/PeriodicBatching
- Size: 26.4 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://barradas.visualstudio.com/Contributions/_build/latest?definitionId=26&branchName=develop)
[](https://sonarcloud.io/dashboard?id=ThiagoBarradas_periodic-batching)
[](https://www.nuget.org/packages/PeriodicBatching/)
[](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`
