Example #1
0
        public IScheduler ConfigureScheduler(IServiceProvider provider, SchedulerConfiguration configuration)
        {
            NameValueCollection properties = new NameValueCollection()
            {
                { "quartz.scheduler.instanceName", "DefaultScheduler" },
                { "quartz.scheduler.instanceId", "auto" },
                { "quartz.jobStore.type", "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" },
                { "quartz.jobStore.useProperties", "true" },
                { "quartz.jobStore.dataSource", "default" },
                { "uartz.jobStore.tablePrefix", "QRTZ_" },
                { "quartz.jobStore.lockHandler.type", "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" },
                { "quartz.dataSource.default.connectionString", configuration.ConnectionString },
                { "quartz.dataSource.default.provider", "SqlServer" },
                { "quartz.serializer.type", "json" },
                { "quartz.jobStore.clustered", "true" },
                { "quartz.jobStore.driverDelegateType", "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz" },
            };

            // First we must get a reference to a scheduler
            var factory   = new StdSchedulerFactory(properties);
            var scheduler = factory.GetScheduler().GetAwaiter().GetResult();

            scheduler.JobFactory = new InjectableJobFactory(provider);

            return(scheduler);
        }
        public static IServiceCollection ComposeScheduler(this IServiceCollection services, IConfiguration configuration)
        {
            var schedulerConfiguration = new SchedulerConfiguration();

            configuration.GetSection("Scheduler")
            .Bind(schedulerConfiguration);

            ComposeQuartzScheduler(services, schedulerConfiguration);
            ComposeJobs(services);

            return(services);
        }
        private static void ComposeQuartzScheduler(IServiceCollection services, SchedulerConfiguration schedulerConfiguration)
        {
            services.AddSingleton(p => {
                var configuration = new QuartzSchedulerConfiguration();
                var scheduler     = configuration.ConfigureScheduler(p, schedulerConfiguration);

                scheduler.AddJob(CreateJob(JobType.Actions), true)
                .GetAwaiter()
                .GetResult();

                return(scheduler);
            });
        }