diff --git a/src/Hangfire.Core/Storage/Monitoring/SucceededJobDto.cs b/src/Hangfire.Core/Storage/Monitoring/SucceededJobDto.cs index ee61476a6..9b90ed045 100644 --- a/src/Hangfire.Core/Storage/Monitoring/SucceededJobDto.cs +++ b/src/Hangfire.Core/Storage/Monitoring/SucceededJobDto.cs @@ -30,6 +30,7 @@ public SucceededJobDto() public JobLoadException LoadException { get; set; } public InvocationData InvocationData { get; set; } public object Result { get; set; } + public long? PerformanceDuration { get; set; } public long? TotalDuration { get; set; } public DateTime? SucceededAt { get; set; } public bool InSucceededState { get; set; } diff --git a/src/Hangfire.SqlServer/SqlServerMonitoringApi.cs b/src/Hangfire.SqlServer/SqlServerMonitoringApi.cs index 66f0a58b1..7630b0075 100644 --- a/src/Hangfire.SqlServer/SqlServerMonitoringApi.cs +++ b/src/Hangfire.SqlServer/SqlServerMonitoringApi.cs @@ -198,18 +198,25 @@ public override JobList SucceededJobs(int @from, int count) count, SucceededState.StateName, descending: true, - (sqlJob, job, invocationData, loadException, stateData) => new SucceededJobDto + (sqlJob, job, invocationData, loadException, stateData) => { - Job = job, - LoadException = loadException, - InvocationData = invocationData, - InSucceededState = SucceededState.StateName.Equals(sqlJob.StateName, StringComparison.OrdinalIgnoreCase), - Result = stateData["Result"], - TotalDuration = stateData.TryGetValue("PerformanceDuration", out var duration) && stateData.TryGetValue("Latency", out var latency) - ? (long?)long.Parse(duration, CultureInfo.InvariantCulture) + (long?)long.Parse(latency, CultureInfo.InvariantCulture) - : null, - SucceededAt = sqlJob.StateChanged, - StateData = stateData + var isPerformanceDurationSet = stateData.TryGetValue("PerformanceDuration", out var duration); + var performanceDuration = + isPerformanceDurationSet ? (long?)long.Parse(duration, CultureInfo.InvariantCulture) : null; + return new SucceededJobDto + { + Job = job, + LoadException = loadException, + InvocationData = invocationData, + InSucceededState = SucceededState.StateName.Equals(sqlJob.StateName, StringComparison.OrdinalIgnoreCase), + Result = stateData["Result"], + PerformanceDuration = performanceDuration, + TotalDuration = isPerformanceDurationSet && stateData.TryGetValue("Latency", out var latency) + ? performanceDuration + (long?)long.Parse(latency, CultureInfo.InvariantCulture) + : null, + SucceededAt = sqlJob.StateChanged, + StateData = stateData + }; })); }