예제 #1
0
        public static async void CreateJobRepeat <T>(string cron, int repeatCount, Dictionary <string, object> keyValues = default, DateTimeOffset startAt = default) where T : IJob
        {
            var name  = NewToken();
            var group = NewToken();
            var job   = JobBuilder.Create <T>()
                        .WithIdentity(name, group)
                        .Build();

            if (keyValues != default)
            {
                foreach (var item in keyValues)
                {
                    job.JobDataMap[item.Key] = item.Value;
                }
            }

            if (startAt == null)
            {
                startAt = DateBuilder.NextGivenSecondDate(DateTime.Now, 1);
            }

            var cronTrigger = TriggerBuilder.Create()
                              .StartAt(startAt)
                              .WithIdentity(name + "Trigger", group + "Trigger")
                              .WithCronSchedule(cron)
                              .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForTotalCount(repeatCount))
                              .Build();

            await scheduler.ScheduleJob(job, cronTrigger);
        }
예제 #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
        //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 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);
        }
예제 #5
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();
        }