Skip to content

Commit d08b1a9

Browse files
committed
internal refactoring
1 parent 8584e8f commit d08b1a9

File tree

6 files changed

+13
-23
lines changed

6 files changed

+13
-23
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
[![nuget](https://img.shields.io/nuget/v/Prometheus.Client.MetricPusher.HostedService?logo=nuget&style=flat-square)](https://www.nuget.org/packages/Prometheus.Client.MetricPusher.HostedService)
55
[![nuget](https://img.shields.io/nuget/dt/Prometheus.Client.MetricPusher.HostedService?logo=nuget&style=flat-square)](https://www.nuget.org/packages/Prometheus.Client.MetricPusher.HostedService)
66
[![codecov](https://img.shields.io/codecov/c/github/prom-client-net/prom-client-metricpusher-hostedservice?logo=codecov&style=flat-square)](https://app.codecov.io/gh/prom-client-net/prom-client-metricpusher-hostedservice)
7-
[![codefactor](https://img.shields.io/codefactor/grade/github/prom-client-net/prom-client-metricpusher-hostedservice?logo=codefactor&style=flat-square)](https://www.codefactor.io/repository/github/prom-client-net/prom-client-metricpusher-hostedservice)
87
[![license](https://img.shields.io/github/license/prom-client-net/prom-client-metricpusher-hostedservice?style=flat-square)](https://github.com/prom-client-net/prom-client-metricpusher-hostedservice/blob/main/LICENSE)
98

109
Extension for [Prometheus.Client](https://github.com/prom-client-net/prom-client)
1110

12-
## Installation
11+
## Install
1312

1413
```sh
1514
dotnet add package Prometheus.Client.MetricPusher.HostedService

src/Defaults.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ namespace Prometheus.Client.MetricPusher.HostedService;
44

55
internal static class Defaults
66
{
7-
internal static TimeSpan Interval = TimeSpan.FromMilliseconds(1000);
7+
internal static TimeSpan PushInterval = TimeSpan.FromMilliseconds(1000);
88
}

src/MetricPusherHostedService.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,11 @@
55

66
namespace Prometheus.Client.MetricPusher.HostedService;
77

8-
public class MetricPusherHostedService : BackgroundService
8+
public class MetricPusherHostedService(IMetricPusher pusher, TimeSpan pushInterval) : BackgroundService
99
{
10-
private readonly IMetricPusher _pusher;
11-
private readonly TimeSpan _interval;
12-
1310
public MetricPusherHostedService(IMetricPusher pusher)
14-
: this(pusher, Defaults.Interval)
15-
{
16-
}
17-
18-
public MetricPusherHostedService(IMetricPusher pusher, TimeSpan interval)
11+
: this(pusher, Defaults.PushInterval)
1912
{
20-
_pusher = pusher;
21-
_interval = interval;
2213
}
2314

2415
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
@@ -28,7 +19,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
2819
await DoPushAsync();
2920
try
3021
{
31-
await Task.Delay(_interval, stoppingToken);
22+
await Task.Delay(pushInterval, stoppingToken);
3223
}
3324
catch (TaskCanceledException)
3425
{
@@ -43,7 +34,7 @@ async Task DoPushAsync()
4334
{
4435
try
4536
{
46-
await _pusher.PushAsync();
37+
await pusher.PushAsync();
4738
}
4839
catch (Exception)
4940
{

src/Prometheus.Client.MetricPusher.HostedService.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net6.0</TargetFramework>
4-
<Description>Prometheus.Client.MetricPusher as HostedService</Description>
4+
<Description>MetricPusher as HostedService</Description>
55
<RepositoryUrl>https://github.com/prom-client-net/prom-client-metricpusher-hostedservice</RepositoryUrl>
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77
</PropertyGroup>

src/ServiceCollectionExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ public static class ServiceCollectionExtensions
88
{
99
public static IServiceCollection AddMetricPusherHostedService(this IServiceCollection services, IMetricPusher pusher)
1010
{
11-
return AddMetricPusherHostedService(services, pusher, Defaults.Interval);
11+
return AddMetricPusherHostedService(services, pusher, Defaults.PushInterval);
1212
}
1313

14-
public static IServiceCollection AddMetricPusherHostedService(this IServiceCollection services, IMetricPusher pusher, TimeSpan interval)
14+
public static IServiceCollection AddMetricPusherHostedService(this IServiceCollection services, IMetricPusher pusher, TimeSpan pushInterval)
1515
{
1616
if (pusher == null)
1717
throw new ArgumentNullException(nameof(pusher));
18-
if (interval == TimeSpan.Zero)
19-
throw new ArgumentOutOfRangeException(nameof(interval));
18+
if (pushInterval == TimeSpan.Zero)
19+
throw new ArgumentOutOfRangeException(nameof(pushInterval));
2020

21-
services.AddSingleton<IHostedService, MetricPusherHostedService>(_ => new MetricPusherHostedService(pusher, interval));
21+
services.AddSingleton<IHostedService, MetricPusherHostedService>(_ => new MetricPusherHostedService(pusher, pushInterval));
2222

2323
return services;
2424
}

tests/ServiceCollecttionExtensionsTests.cs renamed to tests/ServiceCollectionExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Prometheus.Client.MetricPusher.HostedService.Tests;
55

6-
public class ServiceCollecttionExtensionsTests
6+
public class ServiceCollectionExtensionsTests
77
{
88
[Fact]
99
public void AddMetricPusherService_WithNullMetricPusher_ThrowsArgumentNullException()

0 commit comments

Comments
 (0)