diff --git a/src/Tgstation.Server.Api/Models/Internal/Job.cs b/src/Tgstation.Server.Api/Models/Internal/Job.cs
index b8ebe63b70..205faa7707 100644
--- a/src/Tgstation.Server.Api/Models/Internal/Job.cs
+++ b/src/Tgstation.Server.Api/Models/Internal/Job.cs
@@ -1,5 +1,4 @@
using System;
-using System.ComponentModel.DataAnnotations;
namespace Tgstation.Server.Api.Models.Internal
{
@@ -19,14 +18,18 @@ namespace Tgstation.Server.Api.Models.Internal
/// English description of the
///
[Permissions(DenyWrite = true)]
- [Required]
public string Description { get; set; }
+ ///
+ /// Details of any exceptions caught during the
+ ///
+ [Permissions(DenyWrite = true)]
+ public string ExceptionDetails { get; set; }
+
///
/// When the was started
///
[Permissions(DenyWrite = true)]
- [Required]
public DateTimeOffset StartedAt { get; set; }
///
diff --git a/src/Tgstation.Server.Host/Core/JobManager.cs b/src/Tgstation.Server.Host/Core/JobManager.cs
index 94fceefca0..e81f8ece73 100644
--- a/src/Tgstation.Server.Host/Core/JobManager.cs
+++ b/src/Tgstation.Server.Host/Core/JobManager.cs
@@ -55,24 +55,23 @@ namespace Tgstation.Server.Host.Core
/// A representing the running operation
async Task RunJob(Job job, Func operation, CancellationToken cancellationToken)
{
- bool cancelled;
- try
- {
- await operation(cancellationToken).ConfigureAwait(false);
- cancelled = false;
- }
- catch (OperationCanceledException)
- {
- cancelled = true;
- }
-
using (var scope = serviceProvider.CreateScope())
{
var databaseContext = scope.ServiceProvider.GetRequiredService();
job = new Job { Id = job.Id };
databaseContext.Jobs.Attach(job);
- if (cancelled)
+ try
+ {
+ await operation(cancellationToken).ConfigureAwait(false);
+ }
+ catch (OperationCanceledException)
+ {
job.Cancelled = true;
+ }
+ catch (Exception e)
+ {
+ job.ExceptionDetails = e.ToString();
+ }
job.StoppedAt = DateTimeOffset.Now;
await databaseContext.Save(default).ConfigureAwait(false);
}