コード例 #1
0
        private void ConfigureScheduler()
        {
            var scheduleFactory = new StdSchedulerFactory();

            scheduler = scheduleFactory.GetScheduler().Result;

            IJobDetail job      = new JobDetailImpl("Sample1", typeof(JobSampleOne));
            IJobDetail jobTwo   = new JobDetailImpl("Sample2", typeof(JobSampleTwo));
            IJobDetail jobThree = new JobDetailImpl("Sample3", typeof(JobSampleThree));
            ITrigger   trigger  = TriggerBuilder.Create()
                                  .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever(10))
                                  .StartAt(DateTime.Now.AddMinutes(1))
                                  .Build();
            ITrigger triggerTwo = TriggerBuilder.Create()
                                  .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever(6))
                                  .StartAt(DateTime.Now.AddMinutes(4))
                                  .Build();
            ITrigger triggerThree = TriggerBuilder.Create()
                                    .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever(8))
                                    .StartAt(DateTime.Now.AddMinutes(7))
                                    .Build();

            scheduler.ScheduleJob(job, trigger);
            scheduler.ScheduleJob(jobTwo, triggerTwo);
            scheduler.ScheduleJob(jobThree, triggerThree);

            scheduler.Start();
        }
コード例 #2
0
        private static ITrigger DefineIntervalTrigger(string identity, DateTime startTime, IntervalType intervalType, int span, int count)
        {
            var trigger = TriggerBuilder.Create()
                          .WithIdentity(identity, Guid.NewGuid().ToString());

            trigger.StartAt(startTime);
            switch (intervalType)
            {
            case IntervalType.Hourly:
                trigger.WithSchedule(count == 0
                        ? SimpleScheduleBuilder.RepeatHourlyForever(span)
                        : SimpleScheduleBuilder.RepeatHourlyForTotalCount(count, span));
                break;

            case IntervalType.Minutely:
                trigger.WithSchedule(count == 0
                        ? SimpleScheduleBuilder.RepeatMinutelyForever(span)
                        : SimpleScheduleBuilder.RepeatMinutelyForTotalCount(count, span));
                break;

            case IntervalType.Secondly:
                trigger.WithSchedule(count == 0
                        ? SimpleScheduleBuilder.RepeatSecondlyForever(span)
                        : SimpleScheduleBuilder.RepeatSecondlyForTotalCount(count, span));
                break;

            case IntervalType.None:
                break;

            default:
                break;
            }
            return(trigger.Build());
        }
コード例 #3
0
ファイル: Billpay.cs プロジェクト: Josh-Yu/MVC4-Assignment
        //This will create the time trigger of when to fire off the job
        //Also adds to the job and associated trigger to the scheduler service
        //Typically used, when already have a billpayID
        //USED BY MODIFY JOB
        public void createScheduledJobService(int billPayID, int accountNumber, int payeeID, decimal amount, char period, DateTime schedDate)
        {
            Debug.WriteLine("\n\n######### Creating Scheduled Job and trigger");
            //Type changes are needed because the job dictionary cannot accept decimal
            double convertedAmount     = (double)amount;
            string convertedStringDate = schedDate.ToString(dateFormat, CultureInfo.InvariantCulture);


            DateTimeOffset startTime = DateTimeOffset.Now.AddMinutes(1); // schedule for 1 minute in the future to start fireing

            Debug.WriteLine("###### Curent time: " + DateTime.Now.ToString());
            Debug.WriteLine("###### Job Set to Fire at: " + startTime);

            //If statements in charged of increasing the date depending on the type
            if (period == 'S')
            {
                //This creates the trrigger, eg scheduling information
                triggerDetail = TriggerBuilder
                                .Create()
                                .WithIdentity(billPayID.ToString(), "TriggerGrp1")
                                .StartAt(startTime) //Specify when to start first fire
                                                    //Specify when the trigger should start to be active. Eg telling when a job should start to take effect
                                .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForTotalCount(1))
                                .Build();
            }
            else
            {
                //Set the repeat per minute indefintely here
                //This creates the trrigger, eg scheduling information
                triggerDetail = TriggerBuilder
                                .Create()
                                .WithIdentity(billPayID.ToString(), "TriggerGrp1")
                                .StartAt(startTime) //Specify when to start first fire
                                                    //Specify when the trigger should start to be active. Eg telling when a job should start to take effect
                                .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever())
                                                    //.WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever())
                                .Build();
            }


            //Below Creates a job aswell as provide the details and information to the job as a map
            //Create Job with the name "MyJob", Group: "MyJobGroup"
            IJobDetail jobDetail = JobBuilder
                                   .Create(typeof(BillPayJob))
                                   .WithIdentity(billPayID.ToString(), "JobGroup1")
                                   .UsingJobData("Account_Number", accountNumber)
                                   .UsingJobData("Payee_ID", payeeID)
                                   .UsingJobData("Amount", convertedAmount)
                                   .UsingJobData("Date", convertedStringDate) //< can only support string as a date format, no datetime
                                   .UsingJobData("Period", period)
                                   .Build();

            //Associate trigger with job and add to schedule
            sched.ScheduleJob(jobDetail, triggerDetail);
        }
コード例 #4
0
 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());
     });
 }
コード例 #5
0
        public static void AddJobAndTrigger <T>(this IServiceCollectionQuartzConfigurator quartz, IConfiguration config) where T : IJob
        {
            string jobName = typeof(T).Name;
            var    jobKey  = new JobKey(jobName);

            quartz.AddJob <T>(opts => opts.WithIdentity(jobKey));

            quartz.AddTrigger(opts => opts
                              .ForJob(jobKey)
                              .WithIdentity(jobName + "-trigger")
                              .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever()));
        }
コード例 #6
0
        private void DefinirAgendamentoExecucao()
        {
            RegistroLog.RegistarLogInfo(Mensagem.SistemaAgendamentoInicio);

            ISchedulerFactory schedFact = new StdSchedulerFactory();
            ITrigger          trigger;

            this.scheduler = schedFact.GetScheduler();
            //this.scheduler.Start();

            IJobDetail job = JobBuilder.Create <FrmArquivoDataSUS>()
                             .WithIdentity("JobAplicacao", "groupAplicacao")
                             .Build();


            if (this.gbxAcadaMinuto.Enabled)
            {
                trigger = TriggerBuilder.Create()
                          .StartNow()
                          .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever(Convert.ToInt32(this.nudCadaMinuto.Value.ToString())))
                          .Build();
            }
            else
            {
                CronScheduleBuilder cronScheduleBuilder;

                Enumeradores.DiaDaSemana dia = Enumeradores.ConverterObject2DiaDaSemana(this.ddlDiaAgendamento.SelectedValue);

                if (dia == Enumeradores.DiaDaSemana.AllDays)
                {
                    cronScheduleBuilder = CronScheduleBuilder.DailyAtHourAndMinute(Convert.ToInt32(this.nudHora.Value), Convert.ToInt32(this.nudMinuto.Value));
                }
                else
                {
                    cronScheduleBuilder = CronScheduleBuilder.WeeklyOnDayAndHourAndMinute((DayOfWeek)dia, Convert.ToInt32(this.nudHora.Value), Convert.ToInt32(this.nudMinuto.Value));
                }

                trigger = TriggerBuilder.Create()
                          .StartNow()
                          .WithSchedule(cronScheduleBuilder)
                          .Build();
            }

            this.scheduler.ScheduleJob(job, trigger);
            this.scheduler.Start();

            this.lblUltimaExecucao.Text  = "--/--/---- --:--:--";
            this.lblProximaExecucao.Text = trigger.GetNextFireTimeUtc().Value.LocalDateTime.ToString(Constantes.FormatoDataHora);

            RegistroLog.RegistarLogInfo(Mensagem.SistemaAgendamentoFim);
        }
コード例 #7
0
        private void DefinirAgendamentoExecucao()
        {
            RegistroLog.RegistarLogInfo(Mensagem.SistemaAgendamentoInicio);

            ISchedulerFactory schedFact = new StdSchedulerFactory();
            ITrigger          trigger;

            this.scheduler = schedFact.GetScheduler();

            IJobDetail job = JobBuilder.Create <ServicoArquivosDataSUS>()
                             .WithIdentity("JobServico", "groupServico")
                             .Build();


            if (this.executarAcadaMinuto > 0)
            {
                trigger = TriggerBuilder.Create()
                          .StartNow()
                          .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever(this.executarAcadaMinuto))
                          .Build();
            }
            else
            {
                CronScheduleBuilder cronScheduleBuilder;

                Enumeradores.DiaDaSemana dia = Enumeradores.ConverterObject2DiaDaSemana(this.diaAgendamento);

                if (dia == Enumeradores.DiaDaSemana.AllDays)
                {
                    cronScheduleBuilder = CronScheduleBuilder.DailyAtHourAndMinute(this.hora, this.minuto);
                }
                else
                {
                    cronScheduleBuilder = CronScheduleBuilder.WeeklyOnDayAndHourAndMinute((DayOfWeek)dia, this.hora, this.minuto);
                }

                trigger = TriggerBuilder.Create()
                          .StartNow()
                          .WithSchedule(cronScheduleBuilder)
                          .Build();
            }

            this.scheduler.ScheduleJob(job, trigger);
            this.scheduler.Start();

            RegistroLog.RegistarLogInfo(Mensagem.ServicoProximaExecucao + " - " + trigger.GetNextFireTimeUtc().Value.LocalDateTime.ToString(Constantes.FormatoDataHora));

            RegistroLog.RegistarLogInfo(Mensagem.SistemaAgendamentoFim);
        }
コード例 #8
0
        private static ITrigger DefineIntervalTrigger(string _identity, DateTime _startTime, IntervalType _intervalType, int span, int count)
        {
            ITrigger trigger;
            var      _trigger = TriggerBuilder.Create()
                                .WithIdentity(_identity, Guid.NewGuid().ToString());

            _trigger.StartAt(_startTime);
            switch (_intervalType)
            {
            case IntervalType.Hourly:
                if (count == 0)
                {
                    _trigger.WithSchedule(SimpleScheduleBuilder.RepeatHourlyForever(span));
                }
                else
                {
                    _trigger.WithSchedule(SimpleScheduleBuilder.RepeatHourlyForTotalCount(count, span));
                }
                break;

            case IntervalType.Minutely:
                if (count == 0)
                {
                    _trigger.WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever(span));
                }
                else
                {
                    _trigger.WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForTotalCount(count, span));
                }
                break;

            case IntervalType.Secondly:
                if (count == 0)
                {
                    _trigger.WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever(span));
                }
                else
                {
                    _trigger.WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForTotalCount(count, span));
                }
                break;

            default:
                break;
            }
            trigger = _trigger.Build();
            return(trigger);
        }
コード例 #9
0
        public async Task TestAcquireTriggers()
        {
            ISchedulerSignaler schedSignaler = new SampleSignaler();
            ITypeLoadHelper    loadHelper    = new SimpleTypeLoadHelper();

            loadHelper.Initialize();

            var store = new RavenJobStore  {
                Database = "QuartzTest",
                Urls     = "[\"http://localhost:8080\"]"
            };
            await store.Initialize(loadHelper, schedSignaler);

            await store.SchedulerStarted();

            // Setup: Store jobs and triggers.
            var startTime0 = DateTime.UtcNow.AddMinutes(1).ToUniversalTime(); // a min from now.

            for (var i = 0; i < 10; i++)
            {
                var startTime = startTime0.AddMinutes(i * 1); // a min apart
                var job       = JobBuilder.Create <NoOpJob>().WithIdentity("job" + i).Build();
                var schedule  = SimpleScheduleBuilder.RepeatMinutelyForever(2);
                var trigger   = (IOperableTrigger)TriggerBuilder.Create().WithIdentity("trigger" + i)
                                .WithSchedule(schedule).ForJob(job).StartAt(startTime).Build();

                // Manually trigger the first fire time computation that scheduler would do. Otherwise
                // the store.acquireNextTriggers() will not work properly.
                var fireTime = trigger.ComputeFirstFireTimeUtc(null);
                Assert.AreEqual(true, fireTime != null);

                await store.StoreJobAndTrigger(job, trigger);
            }

            // Test acquire one trigger at a time
            for (var i = 0; i < 10; i++)
            {
                DateTimeOffset noLaterThan = startTime0.AddMinutes(i);
                var            maxCount    = 1;
                var            timeWindow  = TimeSpan.Zero;
                var            triggers    = (await store.AcquireNextTriggers(noLaterThan, maxCount, timeWindow)).ToList();
                Assert.AreEqual(1, triggers.Count);
                Assert.AreEqual("trigger" + i, triggers[0].Key.Name);

                // Let's remove the trigger now.
                await store.RemoveJob(triggers[0].JobKey);
            }
        }
コード例 #10
0
        public void TestAcquireTriggers()
        {
            InitJobStore();

            ISchedulerSignaler schedSignaler = new SampleSignaler();
            ITypeLoadHelper    loadHelper    = new SimpleTypeLoadHelper();

            loadHelper.Initialize();

            var store = new RavenJobStore();

            store.Initialize(loadHelper, schedSignaler);
            store.SchedulerStarted();

            // Setup: Store jobs and triggers.
            DateTime startTime0 = DateTime.UtcNow.AddMinutes(1).ToUniversalTime(); // a min from now.

            for (int i = 0; i < 10; i++)
            {
                DateTime              startTime = startTime0.AddMinutes(i * 1); // a min apart
                IJobDetail            job       = JobBuilder.Create <NoOpJob>().WithIdentity("job" + i).Build();
                SimpleScheduleBuilder schedule  = SimpleScheduleBuilder.RepeatMinutelyForever(2);
                IOperableTrigger      trigger   = (IOperableTrigger)TriggerBuilder.Create().WithIdentity("trigger" + i).WithSchedule(schedule).ForJob(job).StartAt(startTime).Build();

                // Manually trigger the first fire time computation that scheduler would do. Otherwise
                // the store.acquireNextTriggers() will not work properly.
                DateTimeOffset?fireTime = trigger.ComputeFirstFireTimeUtc(null);
                Assert.AreEqual(true, fireTime != null);

                store.StoreJobAndTrigger(job, trigger);
            }

            // Test acquire one trigger at a time
            for (int i = 0; i < 10; i++)
            {
                DateTimeOffset           noLaterThan = startTime0.AddMinutes(i);
                int                      maxCount    = 1;
                TimeSpan                 timeWindow  = TimeSpan.Zero;
                IList <IOperableTrigger> triggers    = store.AcquireNextTriggers(noLaterThan, maxCount, timeWindow);
                Assert.AreEqual(1, triggers.Count);
                Assert.AreEqual("trigger" + i, triggers[0].Key.Name);

                // Let's remove the trigger now.
                store.RemoveJob(triggers[0].JobKey);
            }
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: DwightM/Team4Talent
        static void Main()
        {
            var scheduler = StdSchedulerFactory.GetDefaultScheduler();

            scheduler.Start();

            var job = JobBuilder.Create()
                      .OfType(typeof(NoOpJob))
                      .WithDescription("My first Quartz.NET job")
                      .WithIdentity("A no operation job", "Default")
                      .Build();

            var trigger = TriggerBuilder.Create()
                          .StartNow()
                          .WithDescription("Fires every 5 minutes")
                          .WithIdentity("A trigger that fires every 5 minutes", "Default")
                          .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever(5))
                          .Build();

            scheduler.ScheduleJob(job, trigger);

            var jobGroupNames = scheduler.GetJobGroupNames();

            foreach (var jobGroupName in jobGroupNames)
            {
                var jobKeys = scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupContains(jobGroupName));

                foreach (var jobKey in jobKeys)
                {
                    var jobDetail = scheduler.GetJobDetail(jobKey);

                    var jobTriggers = scheduler.GetTriggersOfJob(jobKey);

                    Console.WriteLine("Job with name '{0}' in group '{1}' having description '{2}' with {3} trigger(s).", jobDetail.Key.Name, jobDetail.Key.Group, jobDetail.Description, jobTriggers.Count);
                }
            }

            Console.WriteLine("\r\nPress any key to quit...");
            Console.ReadKey(true);

            scheduler.Shutdown();
        }
コード例 #12
0
        public void TestAcquireTriggersInBatch()
        {
            ISchedulerSignaler schedSignaler = new SampleSignaler();
            ITypeLoadHelper    loadHelper    = new SimpleTypeLoadHelper();

            loadHelper.Initialize();

            RAMJobStore store = new RAMJobStore();

            store.Initialize(loadHelper, schedSignaler);

            // Setup: Store jobs and triggers.
            DateTimeOffset startTime0 = DateTimeOffset.UtcNow.AddMinutes(1); // a min from now.

            for (int i = 0; i < 10; i++)
            {
                DateTimeOffset        startTime = startTime0.AddMinutes(i); // a min apart
                IJobDetail            job       = JobBuilder.Create <NoOpJob>().WithIdentity("job" + i).Build();
                SimpleScheduleBuilder schedule  = SimpleScheduleBuilder.RepeatMinutelyForever(2);
                IOperableTrigger      trigger   = (IOperableTrigger)TriggerBuilder.Create().WithIdentity("job" + i).WithSchedule(schedule).ForJob(job).StartAt(startTime).Build();

                // Manually trigger the first fire time computation that scheduler would do. Otherwise
                // the store.acquireNextTriggers() will not work properly.
                DateTimeOffset?fireTime = trigger.ComputeFirstFireTimeUtc(null);
                Assert.AreEqual(true, fireTime != null);

                store.StoreJobAndTrigger(job, trigger);
            }

            // Test acquire batch of triggers at a time
            DateTimeOffset           noLaterThan = startTime0.AddMinutes(10);
            int                      maxCount    = 7;
            TimeSpan                 timeWindow  = TimeSpan.FromMinutes(8);
            IList <IOperableTrigger> triggers    = store.AcquireNextTriggers(noLaterThan, maxCount, timeWindow);

            Assert.AreEqual(7, triggers.Count);
            for (int i = 0; i < 7; i++)
            {
                Assert.AreEqual("job" + i, triggers[i].Key.Name);
            }
        }
コード例 #13
0
ファイル: Global.asax.cs プロジェクト: donPabloNow/VaultLife
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();

            scheduler.JobFactory = new RuleJobFactory();
            scheduler.Start();

            // Create a job of Type WriteToConsoleJob
            IJobDetail emaiSendJob = JobBuilder.Create(typeof(EmailSendingJob)).WithIdentity("EmailSendJob", "EmailSendJobGroup").Build();

            //Schedule this job to execute every minute, forever.
            ITrigger emailSendTrigger = TriggerBuilder.Create().WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever()).StartNow().WithIdentity("EmailSendJobTrigger", "EmailSendJobGroup").Build();

            if (!scheduler.CheckExists(emaiSendJob.Key))
            {
                scheduler.ScheduleJob(emaiSendJob, emailSendTrigger);
            }
        }
コード例 #14
0
        public static async Task Main(string[] args)
        {
            var configBuilder = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile(ConfigFile);

            var configuration       = configBuilder.Build();
            var containerBuilder    = new ContainerBuilder();
            var configurationModule = new Autofac.Configuration.ConfigurationModule(configuration);

            containerBuilder.RegisterModule(configurationModule);
            containerBuilder.SetupConfigurations(configuration);
            containerBuilder.RegisterModule <ServiceRegistrations>();
            containerBuilder.RegisterModule(new QuartzAutofacFactoryModule());
            containerBuilder.RegisterModule(new QuartzAutofacJobsModule(typeof(SigningFeedJob).Assembly));

            var container = containerBuilder.Build();

            var job     = JobBuilder.Create <SigningFeedJob>().WithIdentity("SigningFeedJob", "Jobs").Build();
            var trigger = TriggerBuilder.Create()
                          .WithIdentity("SigningFeedJob", "Jobs")
                          .StartNow()
                          .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever(15)).Build();

            var cts = new CancellationTokenSource();

            var scheduler = container.Resolve <IScheduler>();
            await scheduler.ScheduleJob(job, trigger, cts.Token).ConfigureAwait(true);

            await scheduler.Start(cts.Token).ConfigureAwait(true);

            System.Console.ReadLine();

            cts.Cancel();
            await scheduler.Shutdown(cts.Token).ConfigureAwait(true);
        }
コード例 #15
0
        public void AddAndScheduleGenericJob <T>(string jobName, string jobGroupName, string triggerName, string triggerGroupName, QuickRepeatIntervals quickRepeatInterval, int intervalValue, int?nTimes) where T : class
        {
            IScheduler scheduler = GetScheduler();

            JobDetailImpl jobDetail = new JobDetailImpl(jobName, jobGroupName, typeof(T));

            ITrigger trigger = null;

            switch (quickRepeatInterval)
            {
            case QuickRepeatIntervals.EverySecond:
                trigger = TriggerBuilder.Create()
                          .StartNow()
                          .WithIdentity(triggerName, triggerGroupName)
                          .WithSchedule(nTimes.HasValue ? SimpleScheduleBuilder.RepeatSecondlyForTotalCount(nTimes.Value, intervalValue) : SimpleScheduleBuilder.RepeatSecondlyForever(intervalValue))
                          .Build();
                break;

            case QuickRepeatIntervals.EveryMinute:
                trigger = TriggerBuilder.Create()
                          .StartNow()
                          .WithIdentity(triggerName, triggerGroupName)
                          .WithSchedule(nTimes.HasValue ? SimpleScheduleBuilder.RepeatMinutelyForTotalCount(nTimes.Value, intervalValue) : SimpleScheduleBuilder.RepeatMinutelyForever(intervalValue))
                          .Build();
                break;

            case QuickRepeatIntervals.EveryHour:
                trigger = TriggerBuilder.Create()
                          .StartNow()
                          .WithIdentity(triggerName, triggerGroupName)
                          .WithSchedule(nTimes.HasValue ? SimpleScheduleBuilder.RepeatHourlyForTotalCount(nTimes.Value, intervalValue) : SimpleScheduleBuilder.RepeatHourlyForever(intervalValue))
                          .Build();
                break;
            }

            scheduler.ScheduleJob(jobDetail, trigger);
            //scheduler.Shutdown();
        }
コード例 #16
0
 public ITrigger GetJobTrigger()
 => TriggerBuilder.Create()
 .WithIdentity("Clean up old carts trigger")
 .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever(_repeatEveryMinutes))
 .Build();
コード例 #17
0
 public ITrigger GetJobTrigger()
 => TriggerBuilder.Create()
 .WithIdentity("FaultTolerance trigger")
 .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever(_repeatEveryMinutes))
 .Build();