Skip to content

Commit

Permalink
Add configuration transaction scheduled
Browse files Browse the repository at this point in the history
  • Loading branch information
engineering87 committed Nov 5, 2024
1 parent fb225fe commit d8c896f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/OpenSharpTrace.TestApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"ScheduledSharpTrace": {
"TimerIntervalSeconds": 30
},
"ConnectionStrings": {
"TraceDb": "Server=(***;Database=***;Trusted_Connection=True;MultipleActiveResultSets=true"
},
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSharpTrace/OpenSharpTrace.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageProjectUrl>https://github.com/engineering87/OpenSharpTrace</PackageProjectUrl>
<RepositoryUrl>https://github.com/engineering87/OpenSharpTrace</RepositoryUrl>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<Version>4.1.0</Version>
<Version>4.2.0</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// (c) 2022 Francesco Del Re <francesco.delre.87@gmail.com>
// This code is licensed under MIT license (see LICENSE.txt for details)
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
Expand All @@ -11,18 +12,22 @@ namespace OpenSharpTrace.TransactionScheduler
public class ScheduledServiceTransaction : IHostedService
{
private readonly IServiceProvider _services;
private readonly TimeSpan _timerInterval;

private Timer _timer;

public ScheduledServiceTransaction(
IServiceProvider services)
IServiceProvider services,
IConfiguration configuration)
{
_services = services;
var intervalInSeconds = configuration.GetValue<int?>("ScheduledSharpTrace:TimerIntervalSeconds") ?? 60;
_timerInterval = TimeSpan.FromSeconds(intervalInSeconds);
}

public Task StartAsync(CancellationToken cancellationToken)
{
_timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromMinutes(1));
_timer = new Timer(DoWork, null, TimeSpan.Zero, _timerInterval);
return Task.CompletedTask;
}

Expand Down

0 comments on commit d8c896f

Please sign in to comment.