3.0.1.8 Control repository status check on update
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
{
|
||||
internal class SbmHousekeepingService : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
Task housekeepingTask = null;
|
||||
CancellationTokenSource cts = null;
|
||||
int housekeepingInProgressIterationNum = 0;
|
||||
int housekeepingInProgressIterationMax = 3;
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
// Wait for a period before invoking housekeeping.
|
||||
await Task.Delay(TimeSpan.FromHours(1), stoppingToken);
|
||||
|
||||
try
|
||||
{
|
||||
// Check if previous housekeeping is still in progress.
|
||||
if (housekeepingTask != null && !housekeepingTask.IsCompleted)
|
||||
{
|
||||
++housekeepingInProgressIterationNum;
|
||||
|
||||
if (housekeepingInProgressIterationNum >= housekeepingInProgressIterationMax)
|
||||
{
|
||||
SaLogger.Warn($"{SysUtil.Fn} Previous housekeeping processing still in progress after {housekeepingInProgressIterationNum} iterations - cancelling and starting new processing.");
|
||||
cts.Cancel();
|
||||
housekeepingInProgressIterationNum = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Previous housekeeping still in progress.
|
||||
SaLogger.Warn($"{SysUtil.Fn} Previous housekeeping processing still in progress. Counter: {housekeepingInProgressIterationNum}.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
housekeepingTask = Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
cts = CancellationTokenSource.CreateLinkedTokenSource(stoppingToken);
|
||||
DoHousekeeping(cts.Token);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Error($"{SysUtil.Fn} {exc.GetType().Name} performing application housekeeping.\n{ExceptionUtil.GetMessage(exc)}");
|
||||
}
|
||||
}, stoppingToken);
|
||||
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Error($"{SysUtil.Fn} {exc.GetType().Name} invoking application housekeeping.\n{ExceptionUtil.GetMessage(exc)}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DoHousekeeping(CancellationToken ct)
|
||||
{
|
||||
SbmGlobals_Web.Application.DoHousekeeping(ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,16 +10,16 @@ using Microsoft.Net.Http.Headers;
|
||||
using Sarand.BusinessMgr.Net.Core.Web.Middleware;
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
{
|
||||
//=======================================================================
|
||||
public class SbmStartup_Web
|
||||
public class SbmStartup_Web : SacsDisposable
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
@@ -40,6 +40,12 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
@@ -61,12 +67,16 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
// Authentication service.
|
||||
// Required to handle 'Forbidden' responses etc.
|
||||
config.services
|
||||
.AddAuthentication(options => {
|
||||
.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultAuthenticateScheme = "forbidScheme";
|
||||
options.DefaultForbidScheme = "forbidScheme";
|
||||
options.AddScheme<SbmAuthenticationHandler>("forbidScheme", "Handle Forbidden");
|
||||
});
|
||||
|
||||
// Periodic housekeeping.
|
||||
config.services.AddHostedService<SbmHousekeepingService>();
|
||||
|
||||
// Added to support memory caching of sessions.
|
||||
config.services.AddMemoryCache();
|
||||
//config.services.AddDistributedMemoryCache(); - for multiple web servers.
|
||||
@@ -112,7 +122,7 @@ namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||
.AddDataAnnotationsLocalization()
|
||||
// Ignore null values during object serialiation.
|
||||
.AddJsonOptions(options => { options.JsonSerializerOptions.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull; });
|
||||
// Jun24 Was: .AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; });
|
||||
// Jun24 Was: .AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; });
|
||||
|
||||
// Configure localisation middleware.
|
||||
config.services.Configure<RequestLocalizationOptions>
|
||||
|
||||
Reference in New Issue
Block a user