예제 #1
0
        /// <summary>
        /// 程序启动将任务调度表里所有状态为 执行中 任务启动起来
        /// </summary>
        /// <param name="serviceCollection"></param>
        /// <returns></returns>
        public static IApplicationBuilder AddJobService(this IApplicationBuilder app, Func <List <JobCenterOptions> > options)
        {
            using (IServiceScope serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                IJobCenter jobCenter = serviceScope.ServiceProvider.GetService <IJobCenter>();

                List <JobCenterOptions> jobInfoList = options.Invoke();


                if (jobInfoList == null)
                {
                    throw new ArgumentNullException(nameof(options));
                }

                //获取实现直接接口的所有子类
                //Type[] types = AppDomain.CurrentDomain.GetAssemblies()
                //             .SelectMany(a => a.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(Quartz.IJob))))
                //             .ToArray();
                //IJob job = Activator.CreateInstance(personType) as IJob;


                //types.ForEach(/*async*/ (item) =>
                //{
                //    //await jobCenter.AddScheduleJobAsync(item);
                //});

                return(app);
            }
        }
예제 #2
0
 public HostedService(IJobCenter schedulerCenter)
 {
     this.schedulerCenter = schedulerCenter;
 }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="service"></param>
 public SchedulerController(IJobCenter service)
 {
     _service = service;
 }