public JobScheduler(ILoggerFactory loggerFactory, IMutex mutex, JobSchedulerOptions options) { EnsureArg.IsNotNull(loggerFactory, nameof(loggerFactory)); EnsureArg.IsNotNull(options, nameof(options)); this.logger = loggerFactory.CreateLogger <JobScheduler>(); this.mutex = mutex ?? new InProcessMutex(null); this.Options = options; }
public static NaosServicesContextOptions AddJobScheduling( this NaosServicesContextOptions naosOptions, Action <JobSchedulerOptions> optionsAction = null, string section = "naos:scheduling") { EnsureArg.IsNotNull(naosOptions, nameof(naosOptions)); EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context)); // needed for mediator naosOptions.Context.Services.Scan(scan => scan .FromApplicationDependencies(a => !a.FullName.StartsWithAny(new[] { "Microsoft", "System", "Scrutor", "Consul" })) .AddClasses(classes => classes.Where(c => c.Name.EndsWith("JobEventHandler", StringComparison.OrdinalIgnoreCase))) //.FromAssembliesOf(typeof(JobEventHandler<>)) //.AddClasses() .AsImplementedInterfaces()); naosOptions.Context.Services.AddSingleton <IJobScheduler>(sp => { var options = new JobSchedulerOptions( sp.GetRequiredService <ILoggerFactory>(), sp.CreateScope().ServiceProvider.GetService(typeof(IMediator)) as IMediator, new ServiceProviderJobFactory(sp.CreateScope().ServiceProvider)); optionsAction?.Invoke(options); return(new JobScheduler( sp.GetRequiredService <ILoggerFactory>(), sp.CreateScope().ServiceProvider.GetService(typeof(ITracer)) as ITracer, new InProcessMutex(sp.GetRequiredService <ILoggerFactory>()), options)); }); naosOptions.Context.Services.AddSingleton <IHostedService>(sp => new JobSchedulerHostedService(sp.GetRequiredService <ILoggerFactory>(), sp.GetRequiredService <IJobScheduler>())); naosOptions.Context.Messages.Add("naos services builder: job scheduling added"); // TODO: list available commands/handlers naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation { Name = "JobScheduling", EchoRoute = "naos/jobscheduling/echo" }); return(naosOptions); }
public static NaosServicesContextOptions AddJobScheduling( this NaosServicesContextOptions naosOptions, Action <JobSchedulerOptions> optionsAction = null, string section = "naos:scheduling") { EnsureArg.IsNotNull(naosOptions, nameof(naosOptions)); EnsureArg.IsNotNull(naosOptions.Context, nameof(naosOptions.Context)); // needed for mediator naosOptions.Context.Services.Scan(scan => scan .FromApplicationDependencies() .AddClasses(classes => classes.Where(c => c.Name.EndsWith("JobEventHandler"))) //.FromAssembliesOf(typeof(JobEventHandler<>)) //.AddClasses() .AsImplementedInterfaces()); naosOptions.Context.Services.AddSingleton <IJobScheduler>(sp => { var settings = new JobSchedulerOptions( sp.GetRequiredService <ILoggerFactory>(), sp.CreateScope().ServiceProvider.GetService(typeof(IMediator)) as IMediator, new ServiceProviderJobFactory(sp)); optionsAction?.Invoke(settings); return(new JobScheduler( sp.GetRequiredService <ILoggerFactory>(), new InProcessMutex(sp.GetRequiredService <ILoggerFactory>()), settings)); }); naosOptions.Context.Services.AddSingleton <IHostedService>(sp => new JobSchedulerHostedService(sp.GetRequiredService <ILoggerFactory>(), sp.GetRequiredService <IJobScheduler>())); naosOptions.Context.Messages.Add($"{LogEventKeys.Startup} naos services builder: job scheduling added"); // TODO: list available commands/handlers naosOptions.Context.Services.AddSingleton(new NaosFeatureInformation { Name = "JobScheduling", EchoRoute = "api/echo/jobscheduling" }); return(naosOptions); }
public static void Start(JobSchedulerOptions options) { IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler.Start(); IJobDetail Job = JobBuilder.Create <performanceEvalutionJob>().Build(); ITrigger Trigger = TriggerBuilder.Create() .WithIdentity("firstTrigger", "group1") .WithDailyTimeIntervalSchedule (s => s.WithIntervalInHours(24) .OnEveryDay() .StartingDailyAt(options.PerformanceScheduleTimeStart) ) .Build(); IJobDetail KPIJob = JobBuilder.Create <KPIEvaluationJob>().Build(); ITrigger KPITrigger = TriggerBuilder.Create() .WithIdentity("secondTrigger", "group1") .WithDailyTimeIntervalSchedule (s => s.WithIntervalInHours(24) .OnEveryDay() .StartingDailyAt(options.KPIEvalutionTimeStart) ) .Build(); IJobDetail routingJob = JobBuilder.Create <automaticRoutingJob>().Build(); ITrigger routingTrigger = TriggerBuilder.Create() .WithIdentity("thirdTrigger", "group1") .WithSimpleSchedule(x => x .WithIntervalInMinutes(options.AutomaticRoutingMinuteStart) .RepeatForever()) .Build(); scheduler.ScheduleJob(Job, Trigger); scheduler.ScheduleJob(KPIJob, KPITrigger); scheduler.ScheduleJob(routingJob, routingTrigger); }
public JobSchedulerHostedService(IJobScheduler jobScheduler, JobSchedulerOptions options) { _jobScheduler = jobScheduler; _options = options; }