static void ConfigureScheduler(ServiceConfigurator <ServiceCore> svc) { svc.ScheduleQuartzJob(q => { //ClearUrlAccessedLog q.WithJob(JobBuilder.Create <ClearUrlAccessedLogJob>() .WithIdentity("ClearUrlAccessedLog", "BackgroundJob") .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithSchedule(SimpleScheduleBuilder.RepeatHourlyForever(24)).Build()); }, true); svc.ScheduleQuartzJob(q => { //SendMessageJob q.WithJob(JobBuilder.Create <SendMessageJob>() .WithIdentity("SendMessageJob", "BackgroundJob") .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever(30)).Build()); }, true); svc.ScheduleQuartzJob(q => { //PMJob q.WithJob(JobBuilder.Create <PMJob>() .WithIdentity("PMJob", "BackgroundJob") .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever(30)).Build()); }, true); }
public static void InitSchedule(ServiceConfigurator <ServiceRunner> svc) { svc.UsingQuartzJobFactory(Container.Resolve <IJobFactory>); InitQuartzJob(); foreach (var job in JobList) { svc.ScheduleQuartzJob(q => { q.WithJob(JobBuilder.Create <ReportAutoGenerateJob>() .WithIdentity(job.Name, AppSettings.JobGroupName) .UsingJobData("JobEntity", JsonConvert.SerializeObject(job)) .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithIdentity($"{job.Name}_trigger", AppSettings.JobGroupName) .WithCronSchedule(job.CornLike) .Build()); CommHelper.AppLogger.InfoFormat("任务 {0} 已完成调度设置", job.Name); }); } CommHelper.AppLogger.Info("调度任务 初始化完毕"); }
public static void Schedule(IContainer container, ServiceConfigurator <JobService> svc) { try { svc.UsingQuartzJobFactory(() => container.Resolve <IJobFactory>()); } catch (Exception) { throw; } foreach (var job in JobList) { svc.ScheduleQuartzJob(q => { q.WithJob(JobBuilder.Create(Type.GetType(JobNamespceFormat.Fmt(job.Name))) .WithIdentity(job.Name, ServiceName) .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithCronSchedule(job.Cron) .Build()); log.InfoFormat("任务 {0} 已完成调度设置", JobNamespceFormat.Fmt(job.Name)); }); } }
/// <summary> /// Добавляет в конфигуратор Quartz задание по расписанию для парсинга album-info.ru. /// </summary> /// <param name="serviceConfigurator">Конфигуратор Quartz.</param> /// <param name="kernel">DI контейнер</param> private static void AlbumInfoParseProcess( ServiceConfigurator <TopshelfService> serviceConfigurator, IKernel kernel) { var resourceRepository = kernel.Get <IBaseRepository <ResourceEntity> >(); var resource = resourceRepository .Queryable().First(r => r.Name.Equals(Resources.AlbumInfoSettings)); var albumInfoParseIsSwitchOn = resource.ParseIsSwitchOn; var albumInfoParsingPeriodInMinutes = resource.ParsePeriodInMinutes; if (!albumInfoParseIsSwitchOn) { return; } ITrigger AlbumInfoParseTrigger() => TriggerBuilder.Create() .WithSimpleSchedule(builder => builder.WithIntervalInMinutes(albumInfoParsingPeriodInMinutes) .WithMisfireHandlingInstructionIgnoreMisfires() .RepeatForever()) .Build(); IJobDetail albumInfoParseTriggerJob = JobBuilder.Create <AlbumInfoParseJob>().Build(); albumInfoParseTriggerJob.JobDataMap.Put(CommonHelper.ContainerKey, kernel); // Запускает парсер album-info.ru serviceConfigurator.ScheduleQuartzJob(jobConfigurator => jobConfigurator .WithJob(() => albumInfoParseTriggerJob) .AddTrigger(AlbumInfoParseTrigger)); }
public static ServiceConfigurator <TService> ScheduleQuartzJobWithTrigger <TService, TJob>( this ServiceConfigurator <TService> configurator, Func <ITrigger> trigger) where TJob : IJob where TService : class { return(configurator.ScheduleQuartzJob(q => { q.WithJob(() => JobBuilder.Create <TJob>().Build()).AddTrigger(trigger); })); }
public static void ConfigureBackgroundJobs(IContainer container, ServiceConfigurator <ITopshelfService> service) { var jobRegistrations = container.ComponentRegistry.Registrations.Where( x => x.Metadata.ContainsKey(JobConfigurationMetaDataItemNames.ComponentType) && x.Metadata[JobConfigurationMetaDataItemNames.ComponentType].ToString().Equals(typeof(IMessageDispatcherJob).Name, StringComparison.CurrentCultureIgnoreCase) ); foreach (var jobRegistration in jobRegistrations) { var componentRegistration = jobRegistration; if ((componentRegistration.Services.First() as KeyedService) == null) { continue; } var jobName = ((KeyedService)componentRegistration.Services.First()).ServiceKey.ToString(); var jobRepeatFrequencyInSeconds = componentRegistration.Metadata.ContainsKey(JobConfigurationMetaDataItemNames.RepeatFrequencyInSeconds) ? int.Parse(componentRegistration.Metadata[JobConfigurationMetaDataItemNames.RepeatFrequencyInSeconds].ToString()) : int.Parse(JobConfigurationMetaDataItemValues.RepeatFrequencyInSeconds); var jobRepeatCount = componentRegistration.Metadata.ContainsKey(JobConfigurationMetaDataItemNames.RepeatCount) ? int.Parse(componentRegistration.Metadata[JobConfigurationMetaDataItemNames.RepeatCount].ToString()) : int.Parse(JobConfigurationMetaDataItemValues.RepeatCount); var componentFullName = componentRegistration.Activator.LimitType.FullName; var componentName = componentRegistration.Activator.LimitType.Name; var componentType = componentRegistration.Activator.LimitType.Assembly.GetType(componentFullName); service.ScheduleQuartzJob(q => { q.WithJob(() => { var jobDetail = new JobDetailImpl(jobName, null, componentType); jobDetail.JobDataMap.Put(JobDataMapKeys.Name, jobName); jobDetail.JobDataMap.Put(JobDataMapKeys.ComponentName, componentName); jobDetail.JobDataMap.Put(JobDataMapKeys.ComponentFullName, componentName); foreach (var item in componentRegistration.Metadata) { jobDetail.JobDataMap.Put(item.Key, item.Value); } return(jobDetail); }); q.AddTrigger(() => TriggerBuilder.Create() .WithIdentity(string.Format("{0}-Trigger", jobName), null) .WithSchedule(jobRepeatCount > 0 ? SimpleScheduleBuilder.RepeatSecondlyForTotalCount(jobRepeatCount, jobRepeatFrequencyInSeconds) : SimpleScheduleBuilder.RepeatSecondlyForever(jobRepeatFrequencyInSeconds) ) .Build()); }); } }
static void ConfigureScheduler(ServiceConfigurator <ServiceCore> svc) { svc.ScheduleQuartzJob(q => { q.WithJob(JobBuilder.Create <HeartbeatJob>() .WithIdentity("Heartbeat", "Maintenance") .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever(30)).Build()); }); }
public void ConfigureBackgroundJobs(ServiceConfigurator <JobsManager> svc) { svc.UsingQuartzJobFactory(() => _container.Resolve <PollerAutofacJobFactory>()); foreach (var taskAdapter in _concreteTask) { string name = taskAdapter.Key; TaskAdapter adapter = taskAdapter.Value; string taskDescription = adapter.TaskDescription; if (adapter.IntervalInSeconds > 0) { svc.ScheduleQuartzJob( q => { q.WithJob( JobBuilder.Create <Job>().WithIdentity(name).WithDescription(taskDescription).Build); q.AddTrigger( () => TriggerBuilder.Create() .WithSchedule( SimpleScheduleBuilder.RepeatSecondlyForever(adapter.IntervalInSeconds)) .Build()); }); } else { svc.ScheduleQuartzJob( q => { q.WithJob( JobBuilder.Create <Job>().WithIdentity(name).WithDescription(taskDescription).Build); q.AddTrigger( () => TriggerBuilder.Create() .WithSimpleSchedule(s => s.RepeatForever() .WithInterval(TimeSpan.FromMilliseconds(1))) .StartNow() .Build()); }); } } }
private static void ConfigureJob(ServiceConfigurator <ServiceCore.ServiceCore> svc, JobConfiguration job) { svc.ScheduleQuartzJob(q => { q.WithJob(JobBuilder.Create(job.JobType) .WithDescription(job.JobDescription) .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever(job.JobTriggerInMinutes)).Build()); }); }
private static void ConfigureBackgroundJobs(ServiceConfigurator <ServiceCore> svc) { svc.UsingQuartzJobFactory(() => _container.Resolve <IJobFactory>()); svc.ScheduleQuartzJob(q => { q.WithJob(JobBuilder.Create <HeartbeatJob>() .WithIdentity("Heartbeat", "Maintenance") .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever(2)).Build()); }); }
private static void ConfigureBackgroundJobs(ServiceConfigurator<ServiceCore> svc) { svc.UsingQuartzJobFactory(() => _container.Resolve<IJobFactory>()); svc.ScheduleQuartzJob(q => { q.WithJob(JobBuilder.Create<HeartbeatJob>() .WithIdentity("Heartbeat", "Maintenance") .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever(2)).Build()); }); }
private static void ConfigureBackgroundJobs(ServiceConfigurator<ServiceCore> svc) { svc.UsingQuartzJobFactory(() => _container.Resolve<IJobFactory>()); var cron = ConfigurationManager.AppSettings.Get("CRON"); svc.ScheduleQuartzJob(q => { q.WithJob(JobBuilder.Create<VapoJob>() .WithIdentity("Vaporize", "Maintenance") .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithCronSchedule(cron).Build()); }); }
public static void InitJob(this ServiceConfigurator <MainService> svc) { var projectName = Assembly.GetEntryAssembly().FullName.Split(",")[0]; foreach (var job in Config.Server.Jobs) { svc.ScheduleQuartzJob(q => { q.WithJob(JobBuilder.Create(Type.GetType($"{projectName}.Jobs.{job.Name}")) .WithIdentity(job.Name, Config.Server.Name) .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithCronSchedule(job.Cron) .Build()); }); } }
/// <summary> /// 初始化调度任务 /// </summary> /// <param name="svc"></param> public static void InitSchedule(ServiceConfigurator <JobService> svc) { svc.UsingQuartzJobFactory(Container.Resolve <IJobFactory>); foreach (var job in JobList) { svc.ScheduleQuartzJob(q => { q.WithJob(JobBuilder.Create(Type.GetType(string.Format(JobNamespceFormat, job.JobName))) .WithIdentity(job.JobName, ServiceName) .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithCronSchedule(job.Cron) .Build()); Log.InfoFormat("任务 {0} 已完成调度设置", string.Format(JobNamespceFormat, job.JobName)); }); } Log.Info("调度任务 初始化完毕"); }
/// <summary> /// Добавляет в конфигуратор Quartz задание по расписанию для уведомлений. /// </summary> /// <param name="serviceConfigurator">Конфигуратор Quartz.</param> /// <param name="kernel">DI контейнер</param> private static void NotificationsProcess( ServiceConfigurator <TopshelfService> serviceConfigurator, IKernel kernel) { try { var notificationsSettingsRepository = kernel.Get <IBaseRepository <NotificationsSettingsEntity> >(); var resource = notificationsSettingsRepository .Queryable().First(r => r.Name.Equals(Resources.NotificationsSettings)); var notificationsIsSwitchOn = resource.NotifyIsSwitchOn; var notificationsPeriodInMinutes = resource.NotifyPeriodInMinutes; if (!notificationsIsSwitchOn) { return; } ITrigger NotificationsTrigger() => TriggerBuilder.Create() .WithSimpleSchedule(builder => builder.WithIntervalInMinutes(notificationsPeriodInMinutes) .WithMisfireHandlingInstructionIgnoreMisfires() .RepeatForever()) .Build(); IJobDetail notificationsTriggerJob = JobBuilder.Create <NotificationsJob>().Build(); notificationsTriggerJob.JobDataMap.Put(CommonHelper.ContainerKey, kernel); // Запускает уведомления serviceConfigurator.ScheduleQuartzJob(jobConfigurator => jobConfigurator .WithJob(() => notificationsTriggerJob) .AddTrigger(NotificationsTrigger)); } catch (Exception e) { Console.WriteLine(e); throw; } }
public void ConfigureBackgroundJobs(ServiceConfigurator<JobsManager> svc) { svc.UsingQuartzJobFactory(() => _container.Resolve<PollerAutofacJobFactory>()); foreach (var taskAdapter in _concreteTask) { string name = taskAdapter.Key; TaskAdapter adapter = taskAdapter.Value; string taskDescription = adapter.TaskDescription; if (adapter.IntervalInSeconds > 0) { svc.ScheduleQuartzJob( q => { q.WithJob( JobBuilder.Create<Job>().WithIdentity(name).WithDescription(taskDescription).Build); q.AddTrigger( () => TriggerBuilder.Create() .WithSchedule( SimpleScheduleBuilder.RepeatSecondlyForever(adapter.IntervalInSeconds)) .Build()); }); } else { svc.ScheduleQuartzJob( q => { q.WithJob( JobBuilder.Create<Job>().WithIdentity(name).WithDescription(taskDescription).Build); q.AddTrigger( () => TriggerBuilder.Create() .WithSimpleSchedule(s => s.RepeatForever() .WithInterval(TimeSpan.FromMilliseconds(1))) .StartNow() .Build()); }); } } }
static void ConfigureScheduler(ServiceConfigurator <ServiceCore> svc) { svc.ScheduleQuartzJob(q => { //ClearUrlAccessedLog q.WithJob(JobBuilder.Create <ClearUrlAccessedLogJob>() .WithIdentity("ClearUrlAccessedLog", "BackgroundJob") .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithSchedule(SimpleScheduleBuilder.RepeatHourlyForever(24)).Build()); }, true); svc.ScheduleQuartzJob(q => { //SendMessageJob q.WithJob(JobBuilder.Create <SendMessageJob>() .WithIdentity("SendMessageJob", "BackgroundJob") .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever(30)).Build()); }, true); svc.ScheduleQuartzJob(q => { //ReorderItemsJob q.WithJob(JobBuilder.Create <ReorderItemsJob>() .WithIdentity("ReorderItemsJob", "BackgroundJob") .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithSchedule(SimpleScheduleBuilder.RepeatHourlyForever(8)).Build()); }, true); svc.ScheduleQuartzJob(q => { //PMJob q.WithJob(JobBuilder.Create <PMJob>() .WithIdentity("PMJob", "BackgroundJob") .Build); q.AddTrigger(() => TriggerBuilder.Create() .WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever(30)).Build()); }, true); //svc.ScheduleQuartzJob(q => //{ // //SLANotificationJob // q.WithJob(JobBuilder.Create<TenantPaymentJob>() // .WithIdentity("TenantPaymentJob", "BackgroundJob") // .Build); // q.AddTrigger(() => TriggerBuilder.Create() // .WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever(30)).Build()); //}, true); //svc.ScheduleQuartzJob(q => //{ // //TenantPaymentJob // q.WithJob(JobBuilder.Create<TenantPaymentJob>() // .WithIdentity("TenantPaymentJob", "BackgroundJob") // .Build); // q.AddTrigger(() => TriggerBuilder.Create() // .WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever(45)).Build()); //}, true); }