Exemplo n.º 1
0
        public JobUpdateResult UpdateJob(MonitoringJob jobInfo)
        {
            var result = new JobUpdateResult();

            Log4NetLogger.Instance.Debug("UpdateJob fired for JobID : " + jobInfo.Id);

            // delete job is inactive
            if (!jobInfo.IsActive)
            {
                jobScheduler.DeleteJob(new JobKey(jobInfo.Id.ToString(), AppSettingsValues.MonitoringUnitId.ToString()));
                result.Success = true;
                result.Message = String.Format("Job with ID {0} has removed successfully.", jobInfo.Id);
                return result;
            }

            var currentTrigger = jobScheduler.GetTrigger(new TriggerKey(jobInfo.Id.ToString(), AppSettingsValues.MonitoringUnitId.ToString()));

            if (currentTrigger == null)
            {
                // TODO : Create new job based on provided information.
                result.Success = true;
                result.Message = String.Format("New Job created with  ID {0}", jobInfo.Id);
                return result;
            }
            else
            {
                var newTrigger = CreateTrigger(jobInfo);
                jobScheduler.RescheduleJob(currentTrigger.Key, newTrigger);
                result.Success = true;

                result.Message = String.Format("Job with Id : "+jobInfo.Id+" has rescheduled and will fire at UTC : {0}", newTrigger.StartTimeUtc);
                return result;
            }
        }
Exemplo n.º 2
0
        private void InitializeJobs(MonitoringJob jobInfo)
        {
            var datamap = new JobDataMap { { "JobSetting", jobInfo.FileJobSettings.FirstOrDefault() } };
            // define the job and tie it to our Mail Dispatcher class
            IJobDetail job = null;
            switch ((JobType)jobInfo.Type)
            {
                case JobType.FileMonitoring:
                    job = JobBuilder.Create<FileMonitoringJob>()
                            .SetJobData(datamap)
                             .WithIdentity(jobInfo.Id.ToString(), AppSettingsValues.MonitoringUnitId.ToString())
                                 .Build();
                    break;
                //TODO: Take care cases of all job type and create instance of job detail accordingly.
            }

            var trigger = CreateTrigger(jobInfo);

            jobScheduler.ScheduleJob(job, trigger);
        }
Exemplo n.º 3
0
        private ITrigger CreateTrigger(MonitoringJob jobInfo)
        {
            // Trigger the job to at specific defined time
            var trigger = TriggerBuilder.Create()
                .WithIdentity(jobInfo.Id.ToString(), AppSettingsValues.MonitoringUnitId.ToString())
                .WithSchedule(ScheduleBuilder.CreateCronScheduleBuilder(jobInfo.JobSchedulingInfoes.FirstOrDefault()))
                .Build();

            return trigger;
        }