1.0.3 The ExecutionTimeInSeconds parameter has been replaced with ExecutionFrequency which accepts values in the format 30s, 10m, 1h or 1d.

master
Tudor Stanciu 2023-10-20 18:50:59 +03:00
parent c84b4e2157
commit e19fdbf11e
5 changed files with 49 additions and 5 deletions

View File

@ -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>

View File

@ -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```.

View File

@ -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.");
}
}
}
}

View File

@ -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)

View File

@ -17,5 +17,5 @@
"Records": [ "@" ],
"Key": "*********",
"Secret": "*********",
"ExecutionTimeInSeconds": 60
"ExecutionFrequency": "60s"
}