예제 #1
0
        /// <summary>
        /// FapJob对象转换成JobInfo
        /// </summary>
        /// <param name="fapJob"></param>
        /// <returns></returns>
        public JobInfo GetJobInfo(FapJob fapJob)
        {
            string assembly = fapJob.JobClass;

            //执行sql的时候默认用此任务调度
            if (fapJob.ExecSql.IsPresent())
            {
                assembly = "Fap.Core.Scheduler.Jobs.ExecSqlJob,Fap.Core";
            }
            if (fapJob.RestfulApi.IsPresent())
            {
                assembly = "Fap.Core.Scheduler.Jobs.RestfulApiJob,Fap.Core";
            }
            if (assembly.IsMissing())
            {
                return(null);
            }
            Type type = Type.GetType(assembly);

            if (type == null)
            {
                return(null);
            }
            IJobDetail job = new JobDetailImpl(fapJob.JobCode, fapJob.JobGroup, type)
            {
                Description = fapJob.JobName
            };

            //执行sql,需要把参数放入上下文环境
            if (fapJob.ExecSql.IsPresent())
            {
                job.JobDataMap.Put(JobConstants.JobExecSqlKey, fapJob.ExecSql);
            }
            if (fapJob.RestfulApi.IsPresent())
            {
                job.JobDataMap.Put(JobConstants.JobRestfulApiKey, fapJob.RestfulApi);
            }
            job.JobDataMap.Put(JobConstants.JobIServiceProviderKey, _provider);
            SimpleTriggerImpl trigger = new SimpleTriggerImpl(fapJob.JobCode, fapJob.JobGroup);

            trigger.StartTimeUtc = new DateTimeOffset(GetDateTime(fapJob.StartTime));
            if (fapJob.EndTime.IsPresent())
            {
                trigger.EndTimeUtc = new DateTimeOffset(GetDateTime(fapJob.EndTime));
            }
            trigger.RepeatInterval = GetRepeateInterval(fapJob.RepeatIntervalType, fapJob.RepeatInterval);
            if (fapJob.RepeatCount > 0)
            {
                trigger.RepeatCount = fapJob.RepeatCount;
            }
            else
            {
                trigger.RepeatCount = SimpleTriggerImpl.RepeatIndefinitely;
            }

            return(new JobInfo()
            {
                Job = job, Trigger = trigger
            });
        }
예제 #2
0
 /// <summary>
 /// 删除一个定时任务
 /// </summary>
 /// <param name="fapJob"></param>
 public async Task RemoveJob(FapJob fapJob)
 {
     await SchedulerManager.Instance.RemoveJob(fapJob.JobCode, fapJob.JobGroup);
 }
예제 #3
0
 /// <summary>
 /// 添加一个定时任务,仅仅不存在时会添加
 /// </summary>
 /// <param name="fapJob"></param>
 public async Task AddJob(FapJob fapJob)
 {
     var     jobManager = new JobManager(_serviceProvider);
     JobInfo job        = jobManager.GetJobInfo(fapJob);
     await SchedulerManager.Instance.AddScheduleJob(job);
 }