source: FarmatikoServices/Services/UpdateDataJob.cs@ 472dd7e

Last change on this file since 472dd7e was f554983, checked in by Dimitar Slezenkovski <dslezenkovski@…>, 4 years ago

Add cron job for updating data, with Quartz.NET

  • Property mode set to 100644
File size: 1.6 KB
Line 
1using FarmatikoData;
2using FarmatikoServices.FarmatikoServiceInterfaces;
3using Microsoft.AspNetCore.Mvc;
4using Microsoft.Extensions.DependencyInjection;
5using Microsoft.Extensions.Logging;
6using Quartz;
7using System;
8using System.Collections.Generic;
9using System.Text;
10using System.Threading.Tasks;
11
12namespace FarmatikoServices.Services
13{
14 [DisallowConcurrentExecution]
15 public class UpdateDataJob : IJob
16 {
17 private readonly ILogger<UpdateDataJob> _logger;
18 private readonly IProcessJSONService _JSONservice;
19 private readonly IServiceScopeFactory _provider;
20 public UpdateDataJob(ILogger<UpdateDataJob> logger, IProcessJSONService JSONservice, IServiceScopeFactory provider)
21 {
22 _logger = logger;
23 _JSONservice = JSONservice;
24 _provider = provider;
25 }
26
27 public async Task Execute(IJobExecutionContext context)
28 {
29 _logger.LogInformation("UpdateData Job started");
30 using (var scope = _provider.CreateScope())
31 {
32 // Resolve the Scoped service
33 var service = scope.ServiceProvider.GetRequiredService<FarmatikoDataContext>();
34 _logger.LogInformation("UpdateData Job started");
35 _JSONservice.DownloadPharmaciesExcel();
36 _JSONservice.GetProcessedHealthcareWorkersFromJSON();
37 _JSONservice.GetProcessedHealthFacilitiesFromJSON();
38 _JSONservice.GetProcessedMedicinesFromJSON();
39
40 }
41
42 await Task.CompletedTask;
43 }
44 }
45}
Note: See TracBrowser for help on using the repository browser.