zoukankan      html  css  js  c++  java
  • Quartz Scheduler

    using Quartz;
    public
    static class SchedulerProgram { public static void Start(IScheduler scheduler = null) { try { Assembly asm = typeof(SchedulerProgram).GetTypeInfo().Assembly; Type[] types = asm.GetTypes(); IDictionary<int, Type> typeMap = new Dictionary<int, Type>(); List<Type> typeList = new List<Type>(); foreach (Type t in types) { if (new List<Type>(t.GetInterfaces()).Contains(typeof(IJobScheduler))) { typeList.Add(t); } } foreach (Type t in typeList) { IJobScheduler schedule = ObjectUtils.InstantiateType<IJobScheduler>(t); if (scheduler == null) { schedule.Run().ConfigureAwait(false); } else { schedule.Run(scheduler).ConfigureAwait(false); } } } catch (Exception ex) { throw ex; } } }
    public class TestJobScheduler : IJobScheduler
        {
    
            public async Task Run(IScheduler scheduler)
            {
                Logger.Writelog("Call job scheduler");
                //创建任务
                IJobDetail job = JobBuilder.Create<TestJob>().
                    WithIdentity("EntityRelationshipTestJob", "CRMJobGroup").
                    UsingJobData("jobschedulename", "EntityRelationshipTestJob").
                    Build();
    
                //创建触发器
                ITrigger trigger = TriggerBuilder.Create().WithIdentity("ContactTrigger", "TimeGroup").WithSimpleSchedule(t => t.WithIntervalInMinutes(30).WithRepeatCount(0)).Build();// test trigger
    
                //添加任务及触发器至调度器中
                await scheduler.ScheduleJob(job, trigger);
    
                //启动
                Logger.Writelog("Start job scheduler");
                await scheduler.Start();
            }
    
            public Task Run()
            {
                throw new NotImplementedException();
            }
        }
    public interface IJobScheduler
        {
            /// <summary>
            /// 
            /// </summary>
            /// <returns></returns>
            Task Run();
    
            /// <summary>
            /// 外部传入scheduler
            /// </summary>
            /// <param name="scheduler"></param>
            /// <returns></returns>
            Task Run(IScheduler scheduler);
        }
    public class TestJob : IJob
        {
    
            public Task Execute(IJobExecutionContext context)
            {//具体的方法
                return Task.FromResult(0);
            }
    
        }
  • 相关阅读:
    ubuntu VirtualBox 网络配置
    Linux Lsof命令详解
    自然用户界面
    [Java]读取文件方法大全
    java设计模式_命令模式 两个不同风格的实现
    创建线程的方法 Thread Runnable
    程序员每天到底可以写几行代码?
    eclipse Javadoc 汉化成中文
    linux jna调用so动态库
    使用GNU Make来管理Java项目,IDE神马都是浮云
  • 原文地址:https://www.cnblogs.com/330774495qq/p/12855842.html
Copyright © 2011-2022 走看看