qol: make Online Services Connect more reliable
This commit is contained in:
@@ -483,6 +483,7 @@
|
||||
<Compile Include="Interop\DiscoServices\LicenseValidationTask.cs" />
|
||||
<Compile Include="Interop\DiscoServices\OnlineServicesAuthentication.cs" />
|
||||
<Compile Include="Interop\DiscoServices\OnlineServicesConnect.cs" />
|
||||
<Compile Include="Interop\DiscoServices\OnlineServicesConnectStartTask.cs" />
|
||||
<Compile Include="Interop\DiscoServices\PluginLibrary.cs" />
|
||||
<Compile Include="Interop\DiscoServices\PluginLibraryUpdateTask.cs" />
|
||||
<Compile Include="Interop\IIS\PreserveIisBindingsTask.cs" />
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace Disco.Services.Interop.DiscoServices
|
||||
token = null;
|
||||
tokenExpires = null;
|
||||
|
||||
ThreadPool.QueueUserWorkItem(async _ => await OnlineServicesConnect.StartAsync());
|
||||
OnlineServicesConnect.QueueStart();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Disco.Services.Logging;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Disco.Services.Interop.DiscoServices
|
||||
@@ -11,7 +12,23 @@ namespace Disco.Services.Interop.DiscoServices
|
||||
|
||||
private static readonly HubConnection connection;
|
||||
|
||||
public static string State => connection.State.ToString();
|
||||
public static ConnectionState State
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (connection.State)
|
||||
{
|
||||
case HubConnectionState.Connected:
|
||||
return ConnectionState.Connected;
|
||||
case HubConnectionState.Connecting:
|
||||
return ConnectionState.Connecting;
|
||||
case HubConnectionState.Reconnecting:
|
||||
return ConnectionState.Reconnecting;
|
||||
default:
|
||||
return ConnectionState.Disconnected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static OnlineServicesConnect()
|
||||
{
|
||||
@@ -23,12 +40,29 @@ namespace Disco.Services.Interop.DiscoServices
|
||||
.WithAutomaticReconnect()
|
||||
.WithStatefulReconnect()
|
||||
.Build();
|
||||
|
||||
connection.Closed += ex =>
|
||||
{
|
||||
SystemLog.LogException("Online Services: Connection Closed", ex);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
connection.Reconnected += connectionId =>
|
||||
{
|
||||
SystemLog.LogInformation("Online Services: Connection Reconnected");
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
connection.Reconnecting += ex =>
|
||||
{
|
||||
SystemLog.LogInformation("Online Services: Connection Reconnecting");
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
}
|
||||
|
||||
public static async Task StartAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (connection.State == HubConnectionState.Disconnected)
|
||||
await connection.StartAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -37,6 +71,12 @@ namespace Disco.Services.Interop.DiscoServices
|
||||
}
|
||||
}
|
||||
|
||||
public static void QueueStart()
|
||||
{
|
||||
if (connection.State == HubConnectionState.Disconnected)
|
||||
ThreadPool.QueueUserWorkItem(async _ => await StartAsync());
|
||||
}
|
||||
|
||||
public static async Task StopAsync()
|
||||
{
|
||||
await connection.StopAsync();
|
||||
@@ -88,5 +128,12 @@ namespace Disco.Services.Interop.DiscoServices
|
||||
public string Content { get; set; }
|
||||
}
|
||||
|
||||
public enum ConnectionState
|
||||
{
|
||||
Disconnected,
|
||||
Connected,
|
||||
Connecting,
|
||||
Reconnecting
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Services.Tasks;
|
||||
using Quartz;
|
||||
using System;
|
||||
|
||||
namespace Disco.Services.Interop.DiscoServices
|
||||
{
|
||||
public class OnlineServicesConnectStartTask : ScheduledTask
|
||||
{
|
||||
public override string TaskName => "Online Services Connect - Start";
|
||||
public override bool LogExceptionsOnly => true;
|
||||
|
||||
public override void InitalizeScheduledTask(DiscoDataContext Database)
|
||||
{
|
||||
// Trigger in 1 + 0-14 minutes
|
||||
var rng = new Random();
|
||||
var delay = rng.Next(15) + 1;
|
||||
|
||||
TriggerBuilder triggerBuilder = TriggerBuilder.Create()
|
||||
.StartAt(DateTimeOffset.Now.AddMinutes(delay))
|
||||
.WithSchedule(SimpleScheduleBuilder.RepeatHourlyForever());
|
||||
|
||||
ScheduleTask(triggerBuilder);
|
||||
}
|
||||
|
||||
protected override void ExecuteTask()
|
||||
{
|
||||
using (var database = new DiscoDataContext())
|
||||
{
|
||||
if (database.DiscoConfiguration.IsActivated)
|
||||
{
|
||||
if (OnlineServicesConnect.State == OnlineServicesConnect.ConnectionState.Disconnected)
|
||||
OnlineServicesConnect.QueueStart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ namespace Disco.Web
|
||||
|
||||
// Connect to Online Services
|
||||
if (Database.DiscoConfiguration.IsActivated)
|
||||
ThreadPool.QueueUserWorkItem(async _ => await OnlineServicesConnect.StartAsync());
|
||||
OnlineServicesConnect.QueueStart();
|
||||
}
|
||||
|
||||
public static void InitializeUpdateEnvironment(DiscoDataContext Database, Version PreviousVersion)
|
||||
|
||||
@@ -70,6 +70,14 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
return RedirectToAction(MVC.Config.Logging.TaskStatus(ts.SessionId));
|
||||
}
|
||||
|
||||
[HttpPost, ValidateAntiForgeryToken, DiscoAuthorize(Claims.Config.System.Show)]
|
||||
public virtual ActionResult OnlineServicesConnectStart()
|
||||
{
|
||||
OnlineServicesConnect.QueueStart();
|
||||
|
||||
return RedirectToAction(MVC.Config.SystemConfig.Index());
|
||||
}
|
||||
|
||||
#region Organisation
|
||||
|
||||
#region Organisation Name
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace Disco.Web.Areas.Config.Models.SystemConfig
|
||||
public bool IsActivated { get; set; }
|
||||
public DateTime? ActivatedOn { get; set; }
|
||||
public string ActivatedBy { get; set; }
|
||||
public string OnlineServicesState { get; set; }
|
||||
public OnlineServicesConnect.ConnectionState OnlineServicesState { get; set; }
|
||||
|
||||
public ScheduledTaskStatus UpdateRunningStatus { get; set; }
|
||||
public DateTime? UpdateNextScheduled { get; set; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@model Disco.Web.Areas.Config.Models.SystemConfig.IndexModel
|
||||
@using Disco.Services.Interop.DiscoServices
|
||||
@{
|
||||
Authorization.Require(Claims.Config.System.Show);
|
||||
|
||||
@@ -83,18 +84,23 @@
|
||||
|
||||
switch (Model.OnlineServicesState)
|
||||
{
|
||||
case "Disconnected":
|
||||
case OnlineServicesConnect.ConnectionState.Disconnected:
|
||||
<div class="info-box error">
|
||||
<p class="fa-p"><i class="fa fa-globe"></i> Disconnected from Online Services</p>
|
||||
@using (Html.BeginForm(MVC.API.System.OnlineServicesConnectStart()))
|
||||
{
|
||||
@Html.AntiForgeryToken()
|
||||
<button type="submit" class="button small">Connect</button>
|
||||
}
|
||||
</div>
|
||||
break;
|
||||
case "Connected":
|
||||
case OnlineServicesConnect.ConnectionState.Connected:
|
||||
<div class="info-box success">
|
||||
<p class="fa-p"><i class="fa fa-globe"></i> Connected to Online Services</p>
|
||||
</div>
|
||||
break;
|
||||
case "Connecting":
|
||||
case "Reconnecting":
|
||||
case OnlineServicesConnect.ConnectionState.Connecting:
|
||||
case OnlineServicesConnect.ConnectionState.Reconnecting:
|
||||
<div class="info-box warning">
|
||||
<p class="fa-p"><i class="fa fa-globe"></i> @Model.OnlineServicesState to Online Services</p>
|
||||
</div>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -170,6 +170,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
public readonly string UpdateADDeviceDescriptions = "UpdateADDeviceDescriptions";
|
||||
public readonly string LicenseCheck = "LicenseCheck";
|
||||
public readonly string UpdateCheck = "UpdateCheck";
|
||||
public readonly string OnlineServicesConnectStart = "OnlineServicesConnectStart";
|
||||
public readonly string UpdateOrganisationName = "UpdateOrganisationName";
|
||||
public readonly string OrganisationLogo = "OrganisationLogo";
|
||||
public readonly string UpdateOrganisationAddress = "UpdateOrganisationAddress";
|
||||
@@ -196,6 +197,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
public const string UpdateADDeviceDescriptions = "UpdateADDeviceDescriptions";
|
||||
public const string LicenseCheck = "LicenseCheck";
|
||||
public const string UpdateCheck = "UpdateCheck";
|
||||
public const string OnlineServicesConnectStart = "OnlineServicesConnectStart";
|
||||
public const string UpdateOrganisationName = "UpdateOrganisationName";
|
||||
public const string OrganisationLogo = "OrganisationLogo";
|
||||
public const string UpdateOrganisationAddress = "UpdateOrganisationAddress";
|
||||
@@ -443,6 +445,17 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
return callInfo;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
partial void OnlineServicesConnectStartOverride(T4MVC_System_Web_Mvc_ActionResult callInfo);
|
||||
|
||||
[NonAction]
|
||||
public override System.Web.Mvc.ActionResult OnlineServicesConnectStart()
|
||||
{
|
||||
var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.OnlineServicesConnectStart);
|
||||
OnlineServicesConnectStartOverride(callInfo);
|
||||
return callInfo;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
partial void UpdateOrganisationNameOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, string OrganisationName, bool redirect);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user