Skip to content

Commit

Permalink
Renamed service
Browse files Browse the repository at this point in the history
  • Loading branch information
0surface committed Jul 27, 2020
1 parent bc7748d commit b6372bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static IHost CreateHostBuilder(string[] args) =>
.ConfigureServices((hostContext, services) =>
{
IConfiguration settings = hostContext.Configuration.GetSection("settings");
services.AddHostedService<ScheduledArchiveService>();
services.AddHostedService<ArchiveExtractionService>();
services.Configure<BackgroundTaskSettings>(settings);
services.AddEventBus(settings)
.AddAutoMapper(typeof(Program))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace arx.Extract.BackgroundTasks.Tasks
{
public class ScheduledArchiveService : BackgroundService
public class ArchiveExtractionService : BackgroundService
{
private readonly BackgroundTaskSettings _settings;
private readonly IMapper _mapper;
private readonly IEventBus _eventBus;
private readonly ILogger<ScheduledArchiveService> _logger;
private readonly ILogger<ArchiveExtractionService> _logger;
private readonly ISubjectRepository _subjectRepo;
private readonly IJobRepository _jobRepository;
private readonly IJobItemRepository _jobItemRepository;
Expand All @@ -34,10 +33,10 @@ public class ScheduledArchiveService : BackgroundService
private readonly IArchiveFetch _archiveFetch;
private readonly ITransformService _transformService;

public ScheduledArchiveService(IOptions<BackgroundTaskSettings> settings,
public ArchiveExtractionService(IOptions<BackgroundTaskSettings> settings,
IMapper mapper,
IEventBus eventBus,
ILogger<ScheduledArchiveService> logger,
ILogger<ArchiveExtractionService> logger,
ISubjectRepository subjectRepo,
IJobRepository jobRepository,
IJobItemRepository jobItemRepository,
Expand Down Expand Up @@ -111,7 +110,7 @@ private async Task RunArchiveExtrationService(CancellationToken stoppingToken)

//TODO: Publish to eventBus
_eventBus.Publish(extractionCompletedEvent);
}
}

private async Task<Guid> ExecuteExtraction(CancellationToken stoppingToken)
{
Expand Down Expand Up @@ -279,7 +278,7 @@ private async Task<Guid> ExecuteExtraction(CancellationToken stoppingToken)

//Persist publications to Storage - Batch insert
int saved = await _publicationRepository.BatchSavePublications(entityList);

if (saved == 0)
{
_logger.LogError($"FulfillmentItem {fulfillmentItem.ItemUId} - persisted 0 publications to Storage");
Expand All @@ -298,7 +297,7 @@ private async Task<Guid> ExecuteExtraction(CancellationToken stoppingToken)
//Log fulfillment Item summary
string activeCode = string.IsNullOrEmpty(fulfillmentItem.QuerySubjectCode) ? fulfillmentItem.QuerySubjectGroup : fulfillmentItem.QuerySubjectCode;
string logFulfillmentItem = $"FulfillmentItem [{fulfillmentItem.ItemUId}] - Subject Query [{activeCode}] - Started @{fulfillmentItem.JobItemStartDate} - Completed @{fulfillmentItem.JobItemCompletedDate} - Fetched ={fulfillmentItem.TotalResults}";

if (savedItem != null)
_logger.LogInformation(logFulfillmentItem);
else
Expand All @@ -312,7 +311,7 @@ private async Task<Guid> ExecuteExtraction(CancellationToken stoppingToken)
newFulfillment.CompleteSuccess = FulfillmentItems.All(x => x.HttpRequestIsSuccess == true)
&& FulfillmentItems.All(x => x.DataExtractionIsSuccess = true);

newFulfillment.JobCompletedDate = DateTime.UtcNow;
newFulfillment.JobCompletedDate = DateTime.UtcNow;
newFulfillment.ProcessingTimeInSeconds = (newFulfillment.JobCompletedDate - newFulfillment.JobStartedDate).TotalSeconds;

//Persist to Storage
Expand All @@ -332,15 +331,15 @@ private async Task<Guid> ExecuteExtraction(CancellationToken stoppingToken)

private static int CalculatePagedRequestCount(int totalAvailable, int fetched)
{
if(fetched == 0)
if (fetched == 0)
return 1;

int yetToFetch = (totalAvailable - fetched);

if ((yetToFetch / fetched) < 1)
if ((yetToFetch / fetched) < 1)
return 1;

int requests = (int)Math.Floor((double)(yetToFetch / fetched));
int requests = (int)Math.Floor((double)(yetToFetch / fetched));

if (yetToFetch % fetched > 0) requests++;

Expand Down

0 comments on commit b6372bb

Please sign in to comment.