-
-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fluent configurations #399
Comments
You can already set the consummation delay from your This would definitely be a breaking change, since right now in that file Any ideas on how we could change the delay to use |
What if add configuration property on Modify QueuingHost.cs like below: internal class QueuingHost : IHostedService, IDisposable
{
private IConfiguration _configuration;
// ...
public Task StartAsync(CancellationToken cancellationToken)
{
TimeSpan consummationDelay = GetConsummationDelay();
this._timer = new Timer((state) => this._signal.Release(), null, TimeSpan.Zero, consummationDelay);
Task.Run(ConsumeQueueAsync);
return Task.CompletedTask;
}
// Change return type from `int` to `TimeSpan`
private TimeSpan GetConsummationDelay()
{
string delayUnit = GetConsummationDelayUnit();
int delayValue = GetConsummationDelayValue(delayUnit);
switch (delayUnit)
{
case "Milliseconds":
return TimeSpan.FromMilliseconds(delayValue);
case "Seconds":
default:
return TimeSpan.FromSeconds(delayValue);
}
}
// Get delay unit ("Milliseconds" or "Seconds").
// This can be improved by using an enum.
private string GetConsummationDelayUnit()
{
var delayUnitSection = this._configuration.GetSection("Coravel:Queue:ConsummationDelayUnit");
return delayUnitSection.Value ?? "Seconds";
}
private int GetConsummationDelayValue(string delayUnit)
{
var delayValueSection = this._configuration.GetSection("Coravel:Queue:ConsummationDelay");
if (int.TryParse(delayValueSection.Value, out int parsedDelay))
{
return parsedDelay;
}
switch (delayUnit)
{
case "Milliseconds":
return 30000;
case "Seconds":
default:
return 30;
}
}
} |
Cool. Do you want to create an PR for this? Could you also add some tests for these methods? You can make the new method public and test it in the unit test project by adding something like this to the top of the class: Thanks! |
AS-IS
Currently, To use Coravel Queue, I have to use functions below
TO-BE
1. Queue Consumption Delay with milliseconds
For better customizable options, I propose that the delay time can be set with milliseconds.
QueuingHost.cs
AS-IS
TO-BE
2. Add Extension Method for Queue Consummation Delay (or other options)
The text was updated successfully, but these errors were encountered: