Add some logging to ReattachInfoHandler. Fix crashing instance auto start.

This commit is contained in:
Jordan Brown
2018-09-08 13:47:57 -04:00
parent 66663fba2a
commit d947eb009b
4 changed files with 31 additions and 6 deletions
@@ -147,7 +147,7 @@ namespace Tgstation.Server.Host.Components
try
{
var sessionControllerFactory = new SessionControllerFactory(processExecutor, byond, byondTopicSender, cryptographySuite, application, gameIoManager, chat, loggerFactory, metadata.CloneMetadata());
var reattachInfoHandler = new ReattachInfoHandler(databaseContextFactory, dmbFactory, metadata.CloneMetadata());
var reattachInfoHandler = new ReattachInfoHandler(databaseContextFactory, dmbFactory, loggerFactory.CreateLogger<ReattachInfoHandler>(), metadata.CloneMetadata());
var watchdogFactory = new WatchdogFactory(chat, sessionControllerFactory, serverUpdater, loggerFactory, reattachInfoHandler, databaseContextFactory, byondTopicSender, eventConsumer, metadata.CloneMetadata());
var watchdog = watchdogFactory.CreateWatchdog(dmbFactory, metadata.DreamDaemonSettings);
eventConsumer.SetWatchdog(watchdog);
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Linq;
using System.Threading;
@@ -22,6 +23,11 @@ namespace Tgstation.Server.Host.Components
/// </summary>
readonly IDmbFactory dmbFactory;
/// <summary>
/// The <see cref="ILogger"/> for the <see cref="ReattachInfoHandler"/>
/// </summary>
readonly ILogger<ReattachInfoHandler> logger;
/// <summary>
/// The <see cref="Api.Models.Instance"/> for the <see cref="ReattachInfoHandler"/>
/// </summary>
@@ -33,16 +39,22 @@ namespace Tgstation.Server.Host.Components
/// <param name="databaseContextFactory">The value of <see cref="databaseContextFactory"/></param>
/// <param name="dmbFactory">The value of <see cref="dmbFactory"/></param>
/// <param name="metadata">The value of <see cref="metadata"/></param>
public ReattachInfoHandler(IDatabaseContextFactory databaseContextFactory, IDmbFactory dmbFactory, Api.Models.Instance metadata)
public ReattachInfoHandler(IDatabaseContextFactory databaseContextFactory, IDmbFactory dmbFactory, ILogger<ReattachInfoHandler> logger, Api.Models.Instance metadata)
{
this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
this.dmbFactory = dmbFactory ?? throw new ArgumentNullException(nameof(dmbFactory));
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
this.metadata = metadata ?? throw new ArgumentNullException(nameof(metadata));
}
/// <inheritdoc />
public Task Save(WatchdogReattachInformation reattachInformation, CancellationToken cancellationToken) => databaseContextFactory.UseContext(async (db) =>
{
if (reattachInformation == null)
throw new ArgumentNullException(nameof(reattachInformation));
logger.LogDebug("Saving reattach information: {0}...", reattachInformation);
var instance = new Models.Instance { Id = metadata.Id };
db.Instances.Attach(instance);
@@ -83,10 +95,15 @@ namespace Tgstation.Server.Host.Components
).ConfigureAwait(false);
if (result == default)
throw new JobException("Unable to load reattach information!");
{
logger.LogDebug("Reattach information not found!");
return null;
}
var bravoDmbTask = dmbFactory.FromCompileJob(result.Bravo.CompileJob, cancellationToken);
return new WatchdogReattachInformation(result, await dmbFactory.FromCompileJob(result.Alpha.CompileJob, cancellationToken).ConfigureAwait(false), await bravoDmbTask.ConfigureAwait(false));
var info = new WatchdogReattachInformation(result, await dmbFactory.FromCompileJob(result.Alpha.CompileJob, cancellationToken).ConfigureAwait(false), await bravoDmbTask.ConfigureAwait(false));
logger.LogDebug("Reattach information loaded: {0}", info);
return info;
}
}
}
@@ -1,4 +1,6 @@
using Tgstation.Server.Host.Models;
using System;
using System.Globalization;
using Tgstation.Server.Host.Models;
namespace Tgstation.Server.Host.Components.Watchdog
{
@@ -35,5 +37,8 @@ namespace Tgstation.Server.Host.Components.Watchdog
if (copy.Bravo != null)
Bravo = new ReattachInformation(copy.Bravo, dmbBravo);
}
/// <inheritdoc />
public override string ToString() => String.Format(CultureInfo.InvariantCulture, "Alpha: {0}, Bravo {1}", Alpha, Bravo);
}
}
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Tgstation.Server.Host.Components.Interop;
using Tgstation.Server.Host.Components.Watchdog;
@@ -34,7 +35,6 @@ namespace Tgstation.Server.Host.Models
/// <summary>
/// The current DreamDaemon reboot state
/// </summary>
[Required]
public RebootState RebootState { get; set; }
/// <summary>
@@ -56,5 +56,8 @@ namespace Tgstation.Server.Host.Models
ProcessId = copy.ProcessId;
RebootState = copy.RebootState;
}
/// <inheritdoc />
public override string ToString() => String.Format(CultureInfo.InvariantCulture, "Process ID: {3}, Access Identifier {4}, Primary: {0}, RebootState: {1}, Port: {2}", IsPrimary, RebootState, Port, ProcessId, AccessIdentifier);
}
}