mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-25 22:01:16 +00:00
finished refactoring and README.md rewrite
This commit is contained in:
@@ -6,7 +6,6 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Hangfire;
|
||||
using Hangfire.States;
|
||||
using MalwareMultiScan.Api.Data;
|
||||
using MalwareMultiScan.Api.Services.Interfaces;
|
||||
using MalwareMultiScan.Shared.Message;
|
||||
using MalwareMultiScan.Shared.Services.Interfaces;
|
||||
@@ -14,6 +13,9 @@ using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MalwareMultiScan.Api.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Job for storing scan results.
|
||||
/// </summary>
|
||||
public class ScanResultJob : IScanResultJob
|
||||
{
|
||||
private readonly IBackgroundJobClient _backgroundJobClient;
|
||||
@@ -21,6 +23,13 @@ namespace MalwareMultiScan.Api.Services
|
||||
private readonly ILogger<ScanResultJob> _logger;
|
||||
private readonly IScanResultService _scanResultService;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize scan result storing job.
|
||||
/// </summary>
|
||||
/// <param name="logger">Logger.</param>
|
||||
/// <param name="httpClientFactory">HTTP client factory.</param>
|
||||
/// <param name="scanResultService">Scan result service.</param>
|
||||
/// <param name="backgroundJobClient">Background job client.</param>
|
||||
public ScanResultJob(
|
||||
ILogger<ScanResultJob> logger,
|
||||
IHttpClientFactory httpClientFactory,
|
||||
@@ -48,14 +57,15 @@ namespace MalwareMultiScan.Api.Services
|
||||
return;
|
||||
|
||||
_backgroundJobClient.Create<IScanResultJob>(
|
||||
x => x.Notify(scanResult.CallbackUrl, resultId, backendId, result), new EnqueuedState());
|
||||
x => x.Notify(scanResult.CallbackUrl, resultId, backendId, result),
|
||||
new EnqueuedState("default"));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task Notify(Uri uri, string resultId, string backendId, ScanResultMessage result)
|
||||
{
|
||||
var cancellationTokenSource = new CancellationTokenSource(
|
||||
TimeSpan.FromSeconds(3));
|
||||
TimeSpan.FromSeconds(5));
|
||||
|
||||
using var httpClient = _httpClientFactory.CreateClient();
|
||||
|
||||
@@ -72,6 +82,8 @@ namespace MalwareMultiScan.Api.Services
|
||||
cancellationTokenSource.Token);
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
_logger.LogInformation($"Sent POST to callback URL {uri}");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
Reference in New Issue
Block a user