1
0
mirror of https://github.com/bitwarden/server synced 2026-01-04 01:23:25 +00:00

connection counter

This commit is contained in:
Kyle Spearrin
2018-08-23 15:48:40 -04:00
parent 43e5f300a7
commit d458d77511
5 changed files with 115 additions and 13 deletions

View 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>();
}
}
}

View 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);
}
}
}