-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve logging for hangfire and audit
- Loading branch information
Showing
18 changed files
with
256 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -349,3 +349,4 @@ MigrationBackup/ | |
*.GhostDoc.xml | ||
*.csv | ||
*.txt | ||
*.clef |
21 changes: 21 additions & 0 deletions
21
...es/Tracker.WebService.EntityFrameworkCore/Domain/Jobs/Commands/BackgroundUpdateCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using MediatR; | ||
using MediatR.CommandQuery.Models; | ||
|
||
namespace Tracker.WebService.Domain.Commands; | ||
|
||
public class BackgroundUpdateCommand : IRequest<CompleteModel> | ||
{ | ||
|
||
public BackgroundUpdateCommand(int id) | ||
{ | ||
Id = id; | ||
} | ||
|
||
public int Id { get; } | ||
|
||
|
||
public override string ToString() | ||
{ | ||
return $"Background Update {Id}"; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...es/Tracker.WebService.EntityFrameworkCore/Domain/Jobs/Handlers/BackgroundUpdateHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using MediatR.CommandQuery.Handlers; | ||
using MediatR.CommandQuery.Models; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
using Tracker.WebService.Domain.Commands; | ||
|
||
namespace Tracker.WebService.Domain.Handlers; | ||
|
||
public class BackgroundUpdateHandler : RequestHandlerBase<BackgroundUpdateCommand, CompleteModel> | ||
{ | ||
public BackgroundUpdateHandler(ILoggerFactory loggerFactory) : base(loggerFactory) | ||
{ | ||
} | ||
|
||
protected override async Task<CompleteModel> Process(BackgroundUpdateCommand request, CancellationToken cancellationToken) | ||
{ | ||
Logger.LogInformation("Process Background Job: {Request}", request); | ||
|
||
await Task.Delay(500, cancellationToken); | ||
|
||
return new CompleteModel { Successful = true }; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
samples/Tracker.WebService.EntityFrameworkCore/Domain/Jobs/JobServiceRegistration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using MediatR; | ||
using MediatR.CommandQuery.Models; | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
||
using Tracker.WebService.Domain.Commands; | ||
using Tracker.WebService.Domain.Handlers; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Tracker.WebService.Domain; | ||
|
||
public class JobServiceRegistration | ||
{ | ||
[RegisterServices] | ||
public void Register(IServiceCollection services) | ||
{ | ||
services.TryAddTransient<IRequestHandler<BackgroundUpdateCommand, CompleteModel>, BackgroundUpdateHandler>(); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
samples/Tracker.WebService.EntityFrameworkCore/Endpoints/JobEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System; | ||
using System.Security.Claims; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using MediatR; | ||
using MediatR.CommandQuery.Endpoints; | ||
using MediatR.CommandQuery.Hangfire; | ||
using MediatR.CommandQuery.Models; | ||
|
||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Routing; | ||
|
||
using Tracker.WebService.Domain.Commands; | ||
|
||
namespace Tracker.WebService.Endpoints; | ||
|
||
[RegisterTransient<IFeatureEndpoint>(Duplicate = DuplicateStrategy.Append)] | ||
public class JobEndpoint : MediatorEndpointBase | ||
{ | ||
public JobEndpoint(IMediator mediator) : base(mediator) | ||
{ | ||
EntityName = "Jobs"; | ||
RoutePrefix = $"/api/{EntityName}"; | ||
} | ||
|
||
public string EntityName { get; } | ||
|
||
public string RoutePrefix { get; } | ||
|
||
|
||
public override void AddRoutes(IEndpointRouteBuilder app) | ||
{ | ||
var group = app.MapGroup(RoutePrefix); | ||
|
||
MapGroup(group); | ||
} | ||
|
||
protected virtual void MapGroup(RouteGroupBuilder group) | ||
{ | ||
group | ||
.MapPost("{id}", RunJob) | ||
.WithTags(EntityName) | ||
.WithName($"RunJob") | ||
.WithSummary("Run job id") | ||
.WithDescription("Run job id"); | ||
} | ||
|
||
private async Task RunJob( | ||
[FromRoute] int id, | ||
ClaimsPrincipal? user = default, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var command = new BackgroundUpdateCommand(id); | ||
await Mediator.Enqueue(command, cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.