自定义jobkey

zw
rszn 5 months ago
parent 604d12c236
commit 30eff70bb3

@ -3,40 +3,30 @@ using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Job; using HybirdFrameworkCore.Job;
using log4net; using log4net;
using Quartz;
using Quartz.Impl.Triggers;
using Repository.System; using Repository.System;
namespace Service.Job; namespace Service.Job;
[Scope] [Scope]
public class TestJob : IMyJob public class TestJob : AbstractCronJob
{ {
private static readonly ILog Log = LogManager.GetLogger(typeof(TestJob)); private static readonly ILog Log = LogManager.GetLogger(typeof(TestJob));
private SysConfigRepository SysConfigRepository = AppInfo.Container.Resolve<SysConfigRepository>(); private SysConfigRepository SysConfigRepository = AppInfo.Container.Resolve<SysConfigRepository>();
public JobKey GetJobKey() protected override Task Handle()
{ {
return JobKey.Create("default", JobKey.DefaultGroup); Log.Info("work");
return Task.CompletedTask;
} }
public ITrigger GetTrigger() protected override string Key()
{ {
return new CronTriggerImpl("d", "d", "0/5 * * * * ?"); return "test-job";
} }
public Task Execute(IJobExecutionContext context) protected override string Cron()
{
try
{
Log.Info($"{SysConfigRepository.GetHashCode()}");
}
catch (Exception e)
{ {
Log.Error(e); return "0/2 * * * * ?";
}
return Task.CompletedTask;
} }
} }

Loading…
Cancel
Save