mirror of
https://github.com/nsnail/NetAdmin.git
synced 2025-12-29 00:55:48 +08:00
@@ -1,5 +1,6 @@
|
||||
using NetAdmin.Domain.Dto.Dependency;
|
||||
using NetAdmin.Domain.Dto.Sys.Job;
|
||||
using NetAdmin.Domain.Dto.Sys.JobRecord;
|
||||
using NetAdmin.Host.Attributes;
|
||||
using NetAdmin.Host.Controllers;
|
||||
using NetAdmin.SysComponent.Application.Modules.Sys;
|
||||
@@ -73,6 +74,22 @@ public sealed class JobController(IJobCache cache) : ControllerBase<IJobCache, I
|
||||
return Cache.QueryAsync(req);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取单个作业记录
|
||||
/// </summary>
|
||||
public Task<QueryJobRecordRsp> RecordGetAsync(QueryJobRecordReq req)
|
||||
{
|
||||
return Cache.RecordGetAsync(req);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询作业记录
|
||||
/// </summary>
|
||||
public Task<PagedQueryRsp<QueryJobRecordRsp>> RecordPagedQueryAsync(PagedQueryReq<QueryJobRecordReq> req)
|
||||
{
|
||||
return Cache.RecordPagedQueryAsync(req);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启用/禁用作业
|
||||
/// </summary>
|
||||
|
||||
@@ -14,8 +14,11 @@ public static class ServiceCollectionExtensions
|
||||
/// </summary>
|
||||
public static IServiceCollection AddSchedules(this IServiceCollection me)
|
||||
{
|
||||
return me.AddSchedule( //
|
||||
builder => builder //
|
||||
.AddJob<ScheduledJob>(false, Triggers.PeriodSeconds(5).SetRunOnStart(true)));
|
||||
return App.WebHostEnvironment.EnvironmentName != Environments.Production
|
||||
? me
|
||||
: me.AddSchedule( //
|
||||
builder => builder //
|
||||
.AddJob<ScheduledJob>(false, Triggers.PeriodSeconds(5).SetRunOnStart(true))
|
||||
.AddJob<FreeScheduledJob>(false, Triggers.PeriodMinutes(1).SetRunOnStart(true)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Furion.Schedule;
|
||||
using NetAdmin.Host.BackgroundRunning;
|
||||
using NetAdmin.SysComponent.Application.Services.Sys.Dependency;
|
||||
|
||||
namespace NetAdmin.SysComponent.Host.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// 释放计划作业
|
||||
/// </summary>
|
||||
public sealed class FreeScheduledJob : WorkBase<FreeScheduledJob>, IJob
|
||||
{
|
||||
private readonly IJobService _jobService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FreeScheduledJob" /> class.
|
||||
/// </summary>
|
||||
public FreeScheduledJob()
|
||||
{
|
||||
_jobService = ServiceProvider.GetService<IJobService>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 具体处理逻辑
|
||||
/// </summary>
|
||||
/// <param name="context">作业执行前上下文</param>
|
||||
/// <param name="stoppingToken">取消任务 Token</param>
|
||||
/// <exception cref="NetAdminGetLockerException">加锁失败异常</exception>
|
||||
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
|
||||
{
|
||||
await WorkflowAsync(true, stoppingToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通用工作流
|
||||
/// </summary>
|
||||
/// <exception cref="NotImplementedException">NotImplementedException</exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException">ArgumentOutOfRangeException</exception>
|
||||
protected override async ValueTask WorkflowAsync(CancellationToken cancelToken)
|
||||
{
|
||||
_ = await _jobService.ReleaseStuckTaskAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public sealed class ScheduledJob : WorkBase<ScheduledJob>, IJob
|
||||
{
|
||||
Duration = sw.ElapsedMilliseconds
|
||||
, HttpMethod = job.HttpMethod
|
||||
, HttpStatusCode = rsp.StatusCode
|
||||
, HttpStatusCode = (int)rsp.StatusCode
|
||||
, JobId = job.Id
|
||||
, RequestBody = job.RequestBody
|
||||
, RequestHeader = _requestHeader
|
||||
|
||||
Reference in New Issue
Block a user