Skip to content

Commit

Permalink
Work Report Hangfire Job implementation - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ychung-mot committed Jan 3, 2020
2 parents 6e01947 + 59739ab commit 61e5971
Show file tree
Hide file tree
Showing 53 changed files with 1,379 additions and 269 deletions.
10 changes: 1 addition & 9 deletions api/Hmcr.Api/Controllers/WorkReportsController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Hangfire;
using Hmcr.Api.Authorization;
using Hmcr.Api.Authorization;
using Hmcr.Api.Controllers.Base;
using Hmcr.Domain.Services;
using Hmcr.Model;
Expand Down Expand Up @@ -66,12 +65,5 @@ public async Task<ActionResult<List<string>>> CheckDuplicateAsync([FromForm] Fil

return Ok(duplicateRecordNumbers);
}

[HttpPost("tests/{id}")]
[RequiresPermission(Permissions.FileUploadWrite)]
public async Task TestAsync(decimal id)
{
await _workRptService.StartBackgroundProcess(id);
}
}
}
6 changes: 5 additions & 1 deletion api/Hmcr.Api/Extensions/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Hangfire;
using Hangfire.SqlServer;
using System;
using Hangfire.AspNetCore;

namespace Hmcr.Api.Extensions
{
Expand Down Expand Up @@ -185,7 +186,10 @@ public static void AddHmcrHangfire(this IServiceCollection services, string conn
DisableGlobalLocks = true
}));

services.AddHangfireServer(options => options.WorkerCount = Environment.ProcessorCount * 3);
services.AddHangfireServer(options =>
{
options.WorkerCount = Environment.ProcessorCount * 3;
});
}
}
}
14 changes: 11 additions & 3 deletions api/Hmcr.Api/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using Hangfire;
using Hangfire.AspNetCore;
using Hmcr.Api.Authentication;
using Hmcr.Api.Extensions;
using Hmcr.Bceid;
using Hmcr.Chris;
using Hmcr.Domain.Hangfire;
using Hmcr.Domain.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

using System;
using System.Linq;

namespace Hmcr.Api
{
Expand Down Expand Up @@ -43,9 +47,9 @@ public void ConfigureServices(IServiceCollection services)
services.AddHmcrHangfire(connectionString);
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISubmissionObjectJobService jobService,
IServiceScopeFactory serviceScopeFactory, IServiceAreaService svcAreaService)
{

if (env.IsDevelopment())
app.UseDeveloperExceptionPage();

Expand All @@ -58,6 +62,10 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseHmcrEndpoints();
app.UseHangfireDashboard();
app.UseHmcrSwagger(env, Configuration.GetSection("Constants:SwaggerApiUrl").Value);

//Register Hangfire Recurring Jobs
var serviceAreas = svcAreaService.GetAllServiceAreas().Where(x => x.ServiceAreaNumber == 10);
SubmissionObjectJobService.RegisterReportingJobs(serviceAreas);
}
}
}
36 changes: 28 additions & 8 deletions api/Hmcr.Api/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"CONNECTION_STRING":"Server=(localdb)\\mssqllocaldb;Database=HMR_DEV;Trusted_Connection=True;MultipleActiveResultSets=true",
"CONNECTION_STRING": "Server=(localdb)\\mssqllocaldb;Database=HMR_DEV;Trusted_Connection=True;MultipleActiveResultSets=true",
"ChrisUris": {
"OasUri": "https://tstoas2.apps.th.gov.bc.ca",
"MapsUri": "https://tst-maps.th.gov.bc.ca"
},
"ServiceAccount": {
"UserId": "<user>",
"Password": "<pass>"
},
"Serilog": {
"MinimumLevel": {
"Default": "Information"
},
"WriteTo": [
{
"Name": "Async",
"Args": {
"configure": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "hmrlog.log",
"rollingInterval": "Day",
"retainedFileCountLimit": 30,
"buffered": true
}
}
]
}
}
],
"Enrich": [
"FromLogContext"
]
}
}
11 changes: 3 additions & 8 deletions api/Hmcr.Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Hangfire": "Information"
}
},
"AllowedHosts": "*",
"CONNECTION_STRING": "Server=(localdb)\\mssqllocaldb;Database=HMR_DEV;Trusted_Connection=True;MultipleActiveResultSets=true",
"Kestrel": {
Expand Down Expand Up @@ -42,6 +34,9 @@
]
}
}
],
"Enrich": [
"FromLogContext"
]
},
"CHRIS_MAP_URL": "https://prd-maps.th.gov.bc.ca",
Expand Down
Loading

0 comments on commit 61e5971

Please sign in to comment.