IegTools.FluentPollster
1.0.1
See the version list below for details.
dotnet add package IegTools.FluentPollster --version 1.0.1
NuGet\Install-Package IegTools.FluentPollster -Version 1.0.1
<PackageReference Include="IegTools.FluentPollster" Version="1.0.1" />
paket add IegTools.FluentPollster --version 1.0.1
#r "nuget: IegTools.FluentPollster, 1.0.1"
// Install IegTools.FluentPollster as a Cake Addin #addin nuget:?package=IegTools.FluentPollster&version=1.0.1 // Install IegTools.FluentPollster as a Cake Tool #tool nuget:?package=IegTools.FluentPollster&version=1.0.1
IegTools.FluentPollster
FluentPollster provides a user-friendly fluent interface for creating easy-to-read polling tasks.
Why another polling library?
I need polling for two scenarios
- get data from the ViessmannApi
- get Temperatures from 1-Wire Bus DS18B20 sensors
I found that FluentScheduler didn't meet my requirements.
I had some ideas and well it's less than 500 loc at the moment, so that's nothing.
Hey and it's fun.
Usage
To get into the details, explore the Integration-Tests.
Simple polling job
You can add any Action as job to the PollsterBuilder,
specify the poll-intervall and the condition,
build the Pollster and run it.
private IPollster _pollster;
public void SimplePolling()
{
var counter = 0;
var uut = PollsterBuilder.Create()
.AddJob(() => counter++, TimeSpan.FromMilliseconds(100), () => HasWhatSoEverCondition());
_pollster = uut.Build();
// runs only once, so when and how you call it belongs to you
_pollster.Run();
}
Execute the pollster automatically every x minutes, seconds,...
You can add Actions also without any condition,
build the Pollster and run it in automatic-mode.
private IPollster _pollster;
public void AutomaticPolling()
{
var counter = 0;
var uut = PollsterBuilder.Create()
.AddJob(() => counter++, TimeSpan.FromSeconds(5));
_pollster = uut.Build();
// run automatic (like FluentScheduler does it...)
_pollster.RunAutomaticEvery(TimeSpan.FromSeconds(10));
}
Multiple intervall polling job
You can add any Action with multiple intervall/condition combinations as job to the PollsterBuilder,
build the Pollster and run it.
private IPollster _pollster;
public void MultipleIntervallPolling()
{
var counter = 0;
var intervalls = new List<(TimeSpan, Func<bool>)>
{
(TimeSpan.FromSeconds(60), () => Condition1()),
(TimeSpan.FromSeconds(120), () => Condition2()),
};
var uut = PollsterBuilder.Create()
.AddJob(() => counter++, intervalls);
var pollster = uut.Build();
_pollster.Run();
}
Additional settings
The FluentPollster needs no dependency injection but you can inject an ILogger
so you will be informed about any exceptions thrown in your poll actions.
(all other important events are logged as 'Trace' at the moment)
And you can set the maximum number of poll tasks that should be executed during one poll cycle.
_pollster = PollsterBuilder.Create()
.SetLogger(logger)
.SetMaxJobsPerPoll(10)
.AddJob(() => Job1(), TimeSpan.FromSeconds(5));
.AddJob(() => Job2(), TimeSpan.FromSeconds(10));
.Build();
_pollster.RunAutomaticEvery(TimeSpan.FromSeconds(1));
ExtensionMethods
At the moment there is only one ExtensionMethod, you can use
DateTime.Now.IsCurrentMinuteDivisibleBy(...) to force your polling task to run only at 'special' minutes within an hour.
Example:
Use DateTime.Now.IsCurrentMinuteDivisibleBy(5) as condition and your action will be called only in
minute 0, 5, 10, 15 and so on
or:
Use DateTime.Now.IsCurrentMinuteDivisibleBy(15) as condition and your action will be called only in
minute 0, 15, 30 and 45
for further information → IntegrationsTests...
IsCurrentMinuteDivisibleBy(this DateTime time, int everyMinutes, int offsetMinute = 0)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Microsoft.Extensions.Configuration.UserSecrets (>= 7.0.0)
- Microsoft.Extensions.Logging (>= 7.0.0)
- NETStandard.Library (>= 2.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.2.0 | 271 | 10/17/2023 |
2.1.1 | 176 | 5/3/2023 |
2.1.0 | 157 | 5/2/2023 |
2.0.0 | 195 | 4/17/2023 |
1.1.0-rc.1 | 94 | 4/15/2023 |
1.0.1 | 185 | 4/5/2023 |
1.0.0 | 207 | 4/5/2023 |
1.0.0-beta.3 | 110 | 4/4/2023 |
1.0.0-beta.2 | 96 | 4/4/2023 |
1.0.0-beta.1 | 96 | 4/3/2023 |
add logo