Skip to content

Commit

Permalink
Merge pull request #38 from FRACerqueira/v2.0.0
Browse files Browse the repository at this point in the history
V2.0.0
  • Loading branch information
FRACerqueira authored Feb 20, 2024
2 parents 3324963 + f7f8ddd commit 74eb6de
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,18 @@ public class MyBussines
}
```

```csharp
//example of Publisher condition to execute
public class SamplePublishHealth : IHealthCheckPublisher, IHealthCheckPlusPublisher
{
public Func<HealthReport, bool> PublisherCondition => (_) => true;
public Task PublishAsync(HealthReport report, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
```

## Code of Conduct
[**Top**](#table-of-contents)

Expand Down
12 changes: 12 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ public class MyBussines
}
}

...

//example of Publisher condition to execute
public class SamplePublishHealth : IHealthCheckPublisher, IHealthCheckPlusPublisher
{
public Func<HealthReport, bool> PublisherCondition => (_) => true;
public Task PublishAsync(HealthReport report, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}

License
*******

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Microsoft.Extensions.Diagnostics.HealthChecks;
using HealthCheckPlus;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace HealthCheckPlusDemoBackgroudService
{
public class SamplePublishHealth : IHealthCheckPublisher
public class SamplePublishHealth : IHealthCheckPublisher, IHealthCheckPlusPublisher
{
public Func<HealthReport, bool> PublisherCondition => (_) => true;
public Task PublishAsync(HealthReport report, CancellationToken cancellationToken)
{
return Task.CompletedTask;
Expand Down
2 changes: 2 additions & 0 deletions docs/apis/apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

- [IDataHealthPlus](./healthcheckplus.idatahealthplus.md)

- [IHealthCheckPlusPublisher](./healthcheckplus.ihealthcheckpluspublisher.md)

- [IStateHealthChecksPlus](./healthcheckplus.istatehealthchecksplus.md)

## Namespace HealthCheckPlus.options
Expand Down
36 changes: 36 additions & 0 deletions docs/apis/healthcheckplus.ihealthcheckpluspublisher.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# <img align="left" width="100" height="100" src="../images/icon.png">HealthCheckPlus API:IHealthCheckPlusPublisher

[![Build](https://github.com/FRACerqueira/HealthCheckPlus/workflows/Build/badge.svg)](https://github.com/FRACerqueira/HealthCheckPlus/actions/workflows/build.yml)
[![License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://github.com/FRACerqueira/HealthCheckPlus/blob/master/LICENSE)
[![NuGet](https://img.shields.io/nuget/v/HealthCheckPlus)](https://www.nuget.org/packages/HealthCheckPlus/)
[![Downloads](https://img.shields.io/nuget/dt/HealthCheckPlus)](https://www.nuget.org/packages/HealthCheckPlus/)

[**Back to List Api**](./apis.md)

# IHealthCheckPlusPublisher

Namespace: HealthCheckPlus

Represents a publisher of information.

```csharp
public interface IHealthCheckPlusPublisher
```

## Properties

### <a id="properties-publishercondition"/>**PublisherCondition**

The Publisher Condition to execute. Default value is null (always run)

```csharp
public abstract Func<HealthReport, Boolean> PublisherCondition { get; }
```

#### Property Value

[Func&lt;HealthReport, Boolean&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.func-2)<br>


- - -
[**Back to List Api**](./apis.md)
12 changes: 12 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,18 @@ public class MyBussines
}
```

```csharp
//example of Publisher condition to execute
public class SamplePublishHealth : IHealthCheckPublisher, IHealthCheckPlusPublisher
{
public Func<HealthReport, bool> PublisherCondition => (_) => true;
public Task PublishAsync(HealthReport report, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
```

## Code of Conduct
[**Top**](#table-of-contents)

Expand Down
20 changes: 20 additions & 0 deletions src/IHealthCheckPlusPublisher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace HealthCheckPlus
{
/// <summary>
/// Represents a publisher of <see cref="HealthReport"/> information.
/// </summary>
public interface IHealthCheckPlusPublisher
{
/// <summary>
/// The Publisher Condition to execute. Default value is null (always run)
/// </summary>
public Func<HealthReport, bool> PublisherCondition { get; }
}
}
16 changes: 15 additions & 1 deletion src/Internal/HealthCheckPlusBackGroundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,21 @@ private async void CheckHealthAsync()
var tasks = new Task[_publishers.Length];
for (var i = 0; i < _publishers.Length; i++)
{
tasks[i] = RunPublisherAsync(_publishers[i], report, _stopping.Token);
if (_publishers[i].GetType().GetInterface(nameof(IHealthCheckPlusPublisher)) != null)
{
if (((IHealthCheckPlusPublisher)_publishers[i]).PublisherCondition.Invoke(report))
{
tasks[i] = RunPublisherAsync(_publishers[i], report, _stopping.Token);
}
else
{
tasks[i] = Task.Run(() => { });
}
}
else
{
tasks[i] = RunPublisherAsync(_publishers[i], report, _stopping.Token);
}
}
await Task.WhenAll(tasks).ConfigureAwait(false);
}
Expand Down

0 comments on commit 74eb6de

Please sign in to comment.