mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-23 21:12:22 +00:00
code cleanup
This commit is contained in:
parent
b4c5c1a507
commit
cfcfe92784
@ -57,7 +57,7 @@ namespace MalwareMultiScan.Api.Services
|
||||
return;
|
||||
|
||||
_backgroundJobClient.Create<IScanResultJob>(
|
||||
x => x.Notify(scanResult.CallbackUrl, resultId, backendId, result),
|
||||
x => x.Notify(scanResult.CallbackUrl, resultId, backendId, result),
|
||||
new EnqueuedState("default"));
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ namespace MalwareMultiScan.Api.Services
|
||||
cancellationTokenSource.Token);
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
|
||||
_logger.LogInformation($"Sent POST to callback URL {uri}");
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
@ -29,10 +29,10 @@ namespace MalwareMultiScan.Api
|
||||
services.AddConsul(_configuration);
|
||||
services.AddMongoDb(_configuration);
|
||||
services.AddHangfire(_configuration);
|
||||
|
||||
|
||||
services.AddSingleton<IScanResultService, ScanResultService>();
|
||||
services.AddSingleton<IScanResultJob, ScanResultJob>();
|
||||
|
||||
|
||||
services.AddControllers();
|
||||
services.AddHttpClient();
|
||||
}
|
||||
@ -41,9 +41,9 @@ namespace MalwareMultiScan.Api
|
||||
{
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
||||
|
||||
|
||||
app.UseForwardedHeaders();
|
||||
|
||||
|
||||
if (hostEnvironment.IsDevelopment())
|
||||
app.UseHangfireDashboard();
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace MalwareMultiScan.Scanner
|
||||
services.AddConsul(context.Configuration);
|
||||
services.AddScanBackend(context.Configuration);
|
||||
|
||||
services.AddHangfire(context.Configuration,
|
||||
services.AddHangfire(context.Configuration,
|
||||
context.Configuration.GetValue<string>("BACKEND_ID"));
|
||||
|
||||
services.AddSingleton<IProcessRunner, ProcessRunner>();
|
||||
|
@ -19,7 +19,7 @@ namespace MalwareMultiScan.Scanner.Services
|
||||
|
||||
private readonly IConsulClient _consulClient;
|
||||
private readonly AgentServiceRegistration _registration;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initialize consul hosted service.
|
||||
/// </summary>
|
||||
|
@ -18,8 +18,8 @@ namespace MalwareMultiScan.Scanner.Services
|
||||
{
|
||||
private readonly IScanBackend _backend;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly ILogger<ScanBackgroundJob> _logger;
|
||||
private readonly IBackgroundJobClient _jobClient;
|
||||
private readonly ILogger<ScanBackgroundJob> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize scan background job.
|
||||
@ -90,7 +90,7 @@ namespace MalwareMultiScan.Scanner.Services
|
||||
$"Sending scan results with status {result.Status}");
|
||||
|
||||
_jobClient.Create<IScanResultJob>(
|
||||
x => x.Report(message.Id, _backend.Id, result),
|
||||
x => x.Report(message.Id, _backend.Id, result),
|
||||
new EnqueuedState("default"));
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
@ -9,12 +9,12 @@ namespace MalwareMultiScan.Shared.Enums
|
||||
/// Scan is queued.
|
||||
/// </summary>
|
||||
Queued,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Scan succeeded.
|
||||
/// </summary>
|
||||
Succeeded,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Scan failed.
|
||||
/// </summary>
|
||||
|
@ -26,30 +26,30 @@ namespace MalwareMultiScan.Shared.Extensions
|
||||
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,
|
||||
public static void AddHangfire(this IServiceCollection services,
|
||||
IConfiguration configuration, params string[] queues)
|
||||
{
|
||||
if (queues.Length == 0)
|
||||
queues = new[] {"default"};
|
||||
|
||||
services.AddHangfire(options =>
|
||||
|
||||
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)
|
||||
|
@ -11,7 +11,7 @@ namespace MalwareMultiScan.Shared.Message
|
||||
/// Scan result id.
|
||||
/// </summary>
|
||||
public string Id { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Scan file URL.
|
||||
/// </summary>
|
||||
|
@ -18,7 +18,7 @@ namespace MalwareMultiScan.Shared.Services.Interfaces
|
||||
/// <param name="result">Scan result.</param>
|
||||
[AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
|
||||
Task Report(string resultId, string backendId, ScanResultMessage result);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Notify remote URL on scan result.
|
||||
/// </summary>
|
||||
|
@ -28,10 +28,10 @@ namespace MalwareMultiScan.Tests.Api
|
||||
var connection = new MongoClient(_mongoDbRunner.ConnectionString);
|
||||
var database = connection.GetDatabase("Test");
|
||||
var gridFsBucket = new GridFSBucket(database);
|
||||
|
||||
|
||||
_resultService = new ScanResultService(
|
||||
database, gridFsBucket,
|
||||
Mock.Of<IConsulClient>(),
|
||||
database, gridFsBucket,
|
||||
Mock.Of<IConsulClient>(),
|
||||
Mock.Of<IBackgroundJobClient>());
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ namespace MalwareMultiScan.Tests.Api
|
||||
{
|
||||
Duration = 100,
|
||||
Status = ScanResultStatus.Succeeded,
|
||||
Threats = new []{"Test"}
|
||||
Threats = new[] {"Test"}
|
||||
});
|
||||
|
||||
result = await _resultService.GetScanResult(result.Id);
|
||||
|
@ -80,9 +80,9 @@ I.e. when you define `callbackUrl=http://localhost:1234/scan-results`, the POST
|
||||
|
||||
```json
|
||||
{
|
||||
"Status":1,
|
||||
"Duration":5,
|
||||
"Threats":["Malware.Dummy.Result"]
|
||||
"Status": 1,
|
||||
"Duration": 5,
|
||||
"Threats": ["Malware.Dummy.Result"]
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -25,8 +25,6 @@ services:
|
||||
restart: on-failure
|
||||
ports:
|
||||
- "8888:8888"
|
||||
expose:
|
||||
- "8888"
|
||||
depends_on:
|
||||
- api
|
||||
environment:
|
||||
|
Loading…
x
Reference in New Issue
Block a user