mirror of
https://github.com/bitwarden/server
synced 2026-01-04 01:23:25 +00:00
connection counter
This commit is contained in:
40
src/Notifications/Jobs/JobsHostedService.cs
Normal file
40
src/Notifications/Jobs/JobsHostedService.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Jobs;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
|
||||
namespace Bit.Notifications.Jobs
|
||||
{
|
||||
public class JobsHostedService : BaseJobsHostedService
|
||||
{
|
||||
public JobsHostedService(
|
||||
IServiceProvider serviceProvider,
|
||||
ILogger<JobsHostedService> logger,
|
||||
ILogger<JobListener> listenerLogger)
|
||||
: base(serviceProvider, logger, listenerLogger) { }
|
||||
|
||||
public override async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var everyFiveMinutesTrigger = TriggerBuilder.Create()
|
||||
.StartNow()
|
||||
.WithCronSchedule("0 */5 * * * ?")
|
||||
.Build();
|
||||
|
||||
Jobs = new List<Tuple<Type, ITrigger>>
|
||||
{
|
||||
new Tuple<Type, ITrigger>(typeof(LogConnectionCounterJob), everyFiveMinutesTrigger)
|
||||
};
|
||||
|
||||
await base.StartAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public static void AddJobsServices(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<LogConnectionCounterJob>();
|
||||
}
|
||||
}
|
||||
}
|
||||
28
src/Notifications/Jobs/LogConnectionCounterJob.cs
Normal file
28
src/Notifications/Jobs/LogConnectionCounterJob.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core;
|
||||
using Bit.Core.Jobs;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
|
||||
namespace Bit.Notifications.Jobs
|
||||
{
|
||||
public class LogConnectionCounterJob : BaseJob
|
||||
{
|
||||
private readonly ConnectionCounter _connectionCounter;
|
||||
|
||||
public LogConnectionCounterJob(
|
||||
ILogger<LogConnectionCounterJob> logger,
|
||||
ConnectionCounter connectionCounter)
|
||||
: base(logger)
|
||||
{
|
||||
_connectionCounter = connectionCounter;
|
||||
}
|
||||
|
||||
protected override Task ExecuteJobAsync(IJobExecutionContext context)
|
||||
{
|
||||
_logger.LogInformation(Constants.BypassFiltersEventId,
|
||||
"Connection count: {0}", _connectionCounter.GetCount());
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user