mirror of
https://github.com/nsnail/NetAdmin.git
synced 2025-09-17 11:05:34 +08:00
@@ -37,6 +37,13 @@ public record Sys_Job : VersionEntity, IFieldEnabled, IFieldSummary
|
||||
[JsonIgnore]
|
||||
public virtual string JobName { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 上次执行耗时
|
||||
/// </summary>
|
||||
[Column]
|
||||
[JsonIgnore]
|
||||
public virtual long? LastDuration { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 上次执行时间
|
||||
/// </summary>
|
||||
|
@@ -43,6 +43,10 @@ public sealed record QueryJobRsp : Sys_Job
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public override string JobName { get; init; }
|
||||
|
||||
/// <inheritdoc cref="Sys_Job.LastDuration" />
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public override long? LastDuration { get; init; }
|
||||
|
||||
/// <inheritdoc cref="Sys_Job.LastExecTime" />
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public override DateTime? LastExecTime { get; init; }
|
||||
|
@@ -68,7 +68,7 @@ public sealed class ScheduledJob : WorkBase<ScheduledJob>, IJob
|
||||
var request = BuildRequest(job);
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
var rsp = await request.SendAsync(cancelToken).ConfigureAwait(false);
|
||||
var rsp = await request.SendAsync(CancellationToken.None).ConfigureAwait(false);
|
||||
if (rsp.StatusCode == HttpStatusCode.Unauthorized) {
|
||||
var loginRsp = await _userService.LoginByUserIdAsync(job.UserId).ConfigureAwait(false);
|
||||
#pragma warning disable S2696
|
||||
@@ -76,12 +76,13 @@ public sealed class ScheduledJob : WorkBase<ScheduledJob>, IJob
|
||||
_refreshToken = loginRsp.RefreshToken;
|
||||
#pragma warning restore S2696
|
||||
request = BuildRequest(job);
|
||||
rsp = await request.SendAsync(cancelToken).ConfigureAwait(false);
|
||||
rsp = await request.SendAsync(CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
await UowManager.AtomicOperateAsync(async () => {
|
||||
var rspBody = await rsp.Content.ReadAsStringAsync(cancelToken).ConfigureAwait(false);
|
||||
var rspBody = await rsp.Content.ReadAsStringAsync(CancellationToken.None)
|
||||
.ConfigureAwait(false);
|
||||
var jobRecord = new CreateJobRecordReq //
|
||||
{
|
||||
Duration = sw.ElapsedMilliseconds
|
||||
@@ -97,7 +98,10 @@ public sealed class ScheduledJob : WorkBase<ScheduledJob>, IJob
|
||||
};
|
||||
_ = await _jobRecordService.CreateAsync(jobRecord).ConfigureAwait(false);
|
||||
await _jobService
|
||||
.FinishJobAsync(job.Adapt<UpdateJobReq>() with { LastStatusCode = rsp.StatusCode })
|
||||
.FinishJobAsync(job.Adapt<UpdateJobReq>() with {
|
||||
LastStatusCode = rsp.StatusCode
|
||||
, LastDuration = jobRecord.Duration
|
||||
})
|
||||
.ConfigureAwait(false);
|
||||
})
|
||||
.ConfigureAwait(false);
|
||||
|
Reference in New Issue
Block a user