mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-23 21:12:22 +00:00
60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using Consul;
|
|
using Hangfire;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace MalwareMultiScan.Shared.Extensions
|
|
{
|
|
/// <summary>
|
|
/// Extensions for IServiceCollection.
|
|
/// </summary>
|
|
[ExcludeFromCodeCoverage]
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Add consul to the service collection and register the node on start.
|
|
/// </summary>
|
|
/// <param name="services">Service collection.</param>
|
|
/// <param name="configuration">Configuration.</param>
|
|
public static void AddConsul(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.AddSingleton<IConsulClient>(new ConsulClient(config =>
|
|
{
|
|
config.Address = configuration.GetValue<Uri>("CONSUL_ADDRESS");
|
|
config.WaitTime = TimeSpan.FromSeconds(120);
|
|
}));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add Hangfire with Redis storage.
|
|
/// </summary>
|
|
/// <param name="services">Service collection.</param>
|
|
/// <param name="configuration">Configuration.</param>
|
|
/// <param name="queues">Queue names.</param>
|
|
public static void AddHangfire(this IServiceCollection services,
|
|
IConfiguration configuration, params string[] queues)
|
|
{
|
|
if (queues.Length == 0)
|
|
queues = new[] {"default"};
|
|
|
|
services.AddHangfire(options =>
|
|
options.UseRedisStorage(configuration.GetValue<string>("REDIS_ADDRESS")));
|
|
|
|
services.AddHangfireServer(options =>
|
|
{
|
|
options.Queues = queues;
|
|
|
|
options.ServerTimeout = TimeSpan.FromSeconds(30);
|
|
options.HeartbeatInterval = TimeSpan.FromSeconds(5);
|
|
options.ServerCheckInterval = TimeSpan.FromSeconds(15);
|
|
|
|
var workerCount = configuration.GetValue<int>("WORKER_COUNT");
|
|
|
|
if (workerCount > 0)
|
|
options.WorkerCount = workerCount;
|
|
});
|
|
}
|
|
}
|
|
} |