1.0.3 The ExecutionTimeInSeconds parameter has been replaced with ExecutionFrequency which accepts values in the format 30s, 10m, 1h or 1d.
parent
c84b4e2157
commit
e19fdbf11e
|
@ -1,6 +1,6 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>1.0.2</Version>
|
||||
<Version>1.0.3</Version>
|
||||
<Authors>Tudor Stanciu</Authors>
|
||||
<Company>STA</Company>
|
||||
<PackageTags>GoDaddyDDNS</PackageTags>
|
||||
|
|
|
@ -21,3 +21,9 @@ To make this worker functional, a minimum configuration is required:
|
|||
## Stack
|
||||
* .NET (C#)
|
||||
* Docker
|
||||
|
||||
## Changelog
|
||||
**1.0.0** - The first release version of the service.
|
||||
**1.0.1** - ConfigureAwait(false) was set for the http client get async calls.
|
||||
**1.0.2** - .NET 6 upgrade.
|
||||
**1.0.3** - The ```ExecutionTimeInSeconds``` parameter has been replaced with ```ExecutionFrequency``` which accepts values in the format ```30s```, ```10m```, ```1h``` or ```1d```.
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace GoDaddyDDNS.Utils
|
||||
{
|
||||
internal static class TimeSpanUtils
|
||||
{
|
||||
public static TimeSpan ParseTimeInterval(string timeInterval)
|
||||
{
|
||||
if (string.IsNullOrEmpty(timeInterval))
|
||||
throw new ArgumentException("Time interval cannot be null or empty.");
|
||||
|
||||
var formatRegex = new Regex(@"^(\d+)([smhd])$", RegexOptions.IgnoreCase);
|
||||
var match = formatRegex.Match(timeInterval);
|
||||
|
||||
if (!match.Success)
|
||||
throw new ArgumentException("Invalid time interval format. Use format like '30s', '10m', '1h', or '1d'.");
|
||||
|
||||
var value = int.Parse(timeInterval.Substring(0, timeInterval.Length - 1));
|
||||
var unit = timeInterval.Substring(timeInterval.Length - 1).ToLower();
|
||||
|
||||
switch (unit)
|
||||
{
|
||||
case "s": // seconds
|
||||
return TimeSpan.FromSeconds(value);
|
||||
case "m": // minutes
|
||||
return TimeSpan.FromMinutes(value);
|
||||
case "h": // hours
|
||||
return TimeSpan.FromHours(value);
|
||||
case "d": // days
|
||||
return TimeSpan.FromDays(value);
|
||||
default:
|
||||
throw new ArgumentException("Invalid time interval unit.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using GoDaddyDDNS.Abstractions;
|
||||
using GoDaddyDDNS.Utils;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
@ -12,15 +13,15 @@ namespace GoDaddyDDNS
|
|||
{
|
||||
private readonly ILogger<Worker> _logger;
|
||||
private readonly IDynamicDNSService _dynamicDNSService;
|
||||
private readonly int _delay;
|
||||
private readonly TimeSpan _delay;
|
||||
|
||||
public Worker(ILogger<Worker> logger, IDynamicDNSService dynamicDNSService, IConfiguration configuration)
|
||||
{
|
||||
_logger=logger;
|
||||
_dynamicDNSService=dynamicDNSService;
|
||||
|
||||
var delayInSeconds = configuration.GetValue<int>("ExecutionTimeInSeconds");
|
||||
_delay = Convert.ToInt32(TimeSpan.FromSeconds(delayInSeconds).TotalMilliseconds);
|
||||
var delay = configuration.GetValue<string>("ExecutionFrequency");
|
||||
_delay = TimeSpanUtils.ParseTimeInterval(delay);
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
|
|
|
@ -17,5 +17,5 @@
|
|||
"Records": [ "@" ],
|
||||
"Key": "*********",
|
||||
"Secret": "*********",
|
||||
"ExecutionTimeInSeconds": 60
|
||||
"ExecutionFrequency": "60s"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue