Add handling for failed auto-updates.

This commit is contained in:
Jared 2021-01-03 16:29:02 -08:00 committed by Jared Goodwin
parent 85898ab590
commit ceaf92f01f
2 changed files with 20 additions and 5 deletions

View File

@ -16,9 +16,10 @@ namespace Remotely.Agent.Services
ConfigService = configService;
}
private ConfigService ConfigService { get; }
private SemaphoreSlim CheckForUpdatesLock { get; } = new SemaphoreSlim(1, 1);
private ConfigService ConfigService { get; }
private SemaphoreSlim InstallLatestVersionLock { get; } = new SemaphoreSlim(1, 1);
private bool PreviousUpdateFailed { get; set; }
private System.Timers.Timer UpdateTimer { get; } = new System.Timers.Timer(TimeSpan.FromHours(6).TotalMilliseconds);
@ -38,12 +39,19 @@ namespace Remotely.Agent.Services
{
try
{
await CheckForUpdatesLock.WaitAsync();
if (EnvironmentHelper.IsDebug)
{
return;
}
await CheckForUpdatesLock.WaitAsync();
if (PreviousUpdateFailed)
{
Logger.Write("Skipping update check due to previous failure. Restart the service to try again, or manually install the update.");
return;
}
var connectionInfo = ConfigService.GetConnectionInfo();
var serverUrl = ConfigService.GetConnectionInfo().Host;
@ -168,7 +176,7 @@ namespace Remotely.Agent.Services
installerPath);
await wc.DownloadFileTaskAsync(
serverUrl + $"/api/AgentUpdate/DownloadPackage/linux/{downloadId}",
serverUrl + $"/API/AgentUpdate/DownloadPackage/linux/{downloadId}",
zipPath);
(await WebRequest.CreateHttp(serverUrl + $"/api/AgentUpdate/ClearDownload/{downloadId}").GetResponseAsync()).Dispose();
@ -182,11 +190,13 @@ namespace Remotely.Agent.Services
}
catch (WebException ex) when (ex.Status == WebExceptionStatus.Timeout)
{
Logger.Write("Timed out while waiting to downloaod update.", Shared.Enums.EventType.Warning);
Logger.Write("Timed out while waiting to download update.", Shared.Enums.EventType.Warning);
PreviousUpdateFailed = true;
}
catch (Exception ex)
{
Logger.Write(ex);
PreviousUpdateFailed = true;
}
finally
{

View File

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Remotely.Server.Services;
using Remotely.Shared.Enums;
@ -69,7 +70,8 @@ namespace Remotely.Server.API
_downloadingAgents.Set(downloadId, string.Empty, cacheOptions);
var waitTime = DateTimeOffset.Now - startWait;
DataService.WriteEvent($"Download started after wait time of {waitTime}. " + "" +
DataService.WriteEvent($"Download started after wait time of {waitTime}. " +
$"ID: {downloadId}. " +
$"Current Downloads: {_downloadingAgents.Count}. Max Allowed: {AppConfig.MaxConcurrentUpdates}", EventType.Debug, null);
@ -87,6 +89,9 @@ namespace Remotely.Server.API
filePath = Path.Combine(HostEnv.WebRootPath, "Downloads", "Remotely-Linux.zip");
break;
default:
DataService.WriteEvent($"Unknown platform requested in { nameof(AgentUpdateController)}: {platform}",
EventType.Warning,
null);
return BadRequest();
}