Ejemplo n.º 1
0
        /// <summary>
        /// 开启QuartzNetJob调度服务
        /// </summary>
        public async static void UseQuartzJobMildd(this IApplicationBuilder app, ILogger <Startup> logger,
                                                   DBSeed dBSeed, SchedulerCenterServer schedulerCenter)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            var tasksQzs = dBSeed.GetTable <TasksQz>().Response?.Where(t => t.IsStart).ToList();

            Console.WriteLine("启动任务数量:" + tasksQzs.Count);
            foreach (var item in tasksQzs)
            {
                var res = await schedulerCenter.AddScheduleJobAsync(item);

                string msg = res.Success ? "启动任务:" + item.Name : "启动任务失败:" + item.Name;
                Console.WriteLine(msg);
                logger.LogInformation(msg);
            }
        }