Пример #1
0
        // 添加Job调度(如果job已经存在,抛出异常)
        public async Task ScheduleJob(JobConfig jobConfig)
        {
            if (await _scheduler.CheckExists(new JobKey(GetJobName(jobConfig), GetJobGroupName(jobConfig)))) // job是否已经存在
            {
                throw new SpriteException("job 已经存在");
            }

            // 判断假期
            if (jobConfig.HolidayCalendarId.HasValue)
            {
                if (!(await _scheduler.GetCalendarNames()).Any(r => r.Contains(jobConfig.HolidayCalendarId.ToString())))
                {
                    await _serviceProvider.DoDapperServiceAsync(DefaultDbConfig, async (unitOfWork) =>
                    {
                        IHolidayCalendarRepository holidayCalendarRepository = ConnectionFactory.GetConnectionProvider(DefaultDbConfig.ConnectionType).GetRepository <IHolidayCalendarRepository>(unitOfWork);

                        var holidayCalendar = await holidayCalendarRepository.GetAsync(jobConfig.HolidayCalendarId.Value);
                        if (holidayCalendar == null)
                        {
                            throw new SpriteException("未找到假期配置信息");
                        }

                        await AddCalendar(holidayCalendar);
                    });
                }
            }

            IJobDetail job     = CreateJobDetail(jobConfig);
            ITrigger   trigger = CreateJobTriggerAsync(jobConfig, null);
            await _scheduler.ScheduleJob(job, trigger);
        }
Пример #2
0
 public async Task StartAsync()
 {
     _scheduler = await new StdSchedulerFactory().GetScheduler();
     await _serviceProvider.DoDapperServiceAsync(DefaultDbConfig, async (unitOfWork) =>
     {
         IJobConfigRepository jobConfigRepository             = ConnectionFactory.GetConnectionProvider(DefaultDbConfig.ConnectionType).GetRepository <IJobConfigRepository>(unitOfWork);
         IHolidayCalendarRepository holidayCalendarRepository = ConnectionFactory.GetConnectionProvider(DefaultDbConfig.ConnectionType).GetRepository <IHolidayCalendarRepository>(unitOfWork);
         var activeJobConfigs = await jobConfigRepository.GetActiveJobConfigs();
         List <HolidayCalendar> holidayCalendars = new List <HolidayCalendar>();
         if (activeJobConfigs.Any(r => r.HolidayCalendarId.HasValue))
         {
             holidayCalendars = (await holidayCalendarRepository.GetAllAsync()).ToList();
             Quartz.Impl.Calendar.HolidayCalendar calendar = new Quartz.Impl.Calendar.HolidayCalendar();
             foreach (var holidayCalendar in holidayCalendars)
             {
                 if (activeJobConfigs.Any(r => r.HolidayCalendarId == holidayCalendar.Id))
                 {
                     await AddCalendar(holidayCalendar);
                 }
             }
         }
         foreach (var activeJobConfig in activeJobConfigs)
         {
             IJobDetail job   = CreateJobDetail(activeJobConfig);
             ITrigger trigger = CreateJobTriggerAsync(activeJobConfig, holidayCalendars);
             await _scheduler.ScheduleJob(job, trigger);
         }
         _scheduler.ListenerManager.AddJobListener(QuartzJobListener, GroupMatcher <JobKey> .AnyGroup());
         await _scheduler.Start();
     });
 }
        public async Task AddHolidayCalendar(HolidayCalendar holidayCalendar)
        {
            holidayCalendar.Id = Guid.NewGuid();
            await _serviceProvider.DoDapperServiceAsync(DefaultDbConfig, async (unitOfWork) =>
            {
                IHolidayCalendarRepository holidayCalendarRepository = ConnectionFactory.GetConnectionProvider(DefaultDbConfig.ConnectionType).GetRepository <IHolidayCalendarRepository>(unitOfWork);
                await holidayCalendarRepository.InsertAsync(holidayCalendar);
            });

            Logger.LogInformation($"AddHolidayCalendar:{JsonConvert.SerializeObject(holidayCalendar)}");
        }
        public async Task UpdateHolidayCalendar(HolidayCalendar holidayCalendar)
        {
            await _serviceProvider.DoDapperServiceAsync(DefaultDbConfig, async (unitOfWork) =>
            {
                IHolidayCalendarRepository holidayCalendarRepository = ConnectionFactory.GetConnectionProvider(DefaultDbConfig.ConnectionType).GetRepository <IHolidayCalendarRepository>(unitOfWork);
                IJobConfigRepository jobConfigRepository             = ConnectionFactory.GetConnectionProvider(DefaultDbConfig.ConnectionType).GetRepository <IJobConfigRepository>(unitOfWork);
                var dbHolidayCalendar = await holidayCalendarRepository.GetAsync(holidayCalendar.Id);
                if (dbHolidayCalendar == null)
                {
                    throw new SpriteException("未找到假期信息");
                }
                await holidayCalendarRepository.UpdateAsync(holidayCalendar);
                var activeJobConfigs = await jobConfigRepository.GetActiveJobConfigs();
                foreach (var activeJobConfig in activeJobConfigs)
                {
                    if (activeJobConfig.HolidayCalendarId.HasValue && activeJobConfig.HolidayCalendarId.Value == holidayCalendar.Id)
                    {
                        await _jobManager.UnScheduleJob(activeJobConfig);
                    }
                }

                await _jobManager.DeleteCalendar(holidayCalendar.Id);

                await _jobManager.AddCalendar(holidayCalendar);

                foreach (var activeJobConfig in activeJobConfigs)
                {
                    if (activeJobConfig.HolidayCalendarId.HasValue && activeJobConfig.HolidayCalendarId.Value == holidayCalendar.Id)
                    {
                        await _jobManager.ScheduleJob(activeJobConfig);
                    }
                }
            });

            Logger.LogInformation($"UpdateHolidayCalendar:{JsonConvert.SerializeObject(holidayCalendar)}");
        }
Пример #5
0
 public HolidayCalendarController(IHolidayCalendarRepository holidaycalendarRepository)
 {
     this.holidaycalendarRepository = holidaycalendarRepository;
 }
 public OrganizationHolidayCalendarController(IOrganizationRepository organizationRepository, IHolidayCalendarRepository holidaycalendarRepository, IOrganizationHolidayCalendarRepository organizationholidaycalendarRepository)
 {
     this.organizationRepository = organizationRepository;
     this.holidaycalendarRepository = holidaycalendarRepository;
     this.organizationholidaycalendarRepository = organizationholidaycalendarRepository;
 }