/// <summary> /// </summary> /// <param name="job"></param> /// <exception cref="ArgumentNullException"><paramref name="job"/> is <see langword="null"/></exception> public void ScheduleJob(IJobSettings job) { if (job == null) { throw new ArgumentNullException(nameof(job)); } _logger.Info($"Scheduling job {job.Name}"); //convert and add them IDictionary map = new Dictionary <string, string> { { "settings", JsonConvert.SerializeObject(job) } }; IJobDetail quartzJob = JobBuilder .Create <DataUpdateJob>() .WithIdentity(job.Name, JobTypes.GetJobType(job)) .UsingJobData(new JobDataMap(map)) .Build(); try { _scheduler.ScheduleJob(quartzJob, CreateTrigger(job)); } catch (Exception ex) { _logger.Error(ex, "Quartz Error scheduling job: " + ex.Message); throw; } }
private dynamic AddJob <T>(IJobsRepository repo) where T : IJobSettings { T jobSettings = this.BindAndValidate <T>(); if (ModelValidationResult.IsValid == false) { return(this.ValidationFailure()); } //make sure name doesn't already exist var existingJob = repo.GetJobDetails(jobSettings.Name, JobTypes.GetJobType(jobSettings)); if (existingJob != null) { return(Negotiate .WithModel(new ErrorResponse( HttpStatusCode.Conflict, "A job with this name already exists", "")) .WithStatusCode(HttpStatusCode.Conflict)); } //add it and return repo.ScheduleJob(jobSettings); return(jobSettings); }
public static void ScheduleJobs <T>(IScheduler scheduler, IEnumerable <T> jobs) where T : IJobSettings { if (jobs == null) { return; } //then convert and add them foreach (IJobSettings job in jobs) { IDictionary map = new Dictionary <string, string> { { "settings", JsonConvert.SerializeObject(job) } }; IJobDetail quartzJob = JobBuilder .Create <DataUpdateJob>() .WithIdentity(job.Name, JobTypes.GetJobType(job)) .UsingJobData(new JobDataMap(map)) .Build(); try { scheduler.ScheduleJob(quartzJob, CreateTrigger(job)); } catch (Exception ex) { var logger = LogManager.GetCurrentClassLogger(); logger.Log(LogLevel.Error, "Quartz Error scheduling job: " + ex.Message); } } }
private static ITrigger CreateTrigger(IJobSettings jobSettings) { ITrigger trigger = TriggerBuilder .Create() .WithSchedule(GetScheduleBuilder(jobSettings)) .WithIdentity(jobSettings.Name, JobTypes.GetJobType(jobSettings)) .Build(); return(trigger); }
private dynamic DeleteJob <T>(IJobsRepository repo) where T : IJobSettings { T jobSettings = this.Bind <T>(); if (jobSettings == null) { return(HttpStatusCode.BadRequest); } //Make sure it exists var existingJob = repo.GetJobDetails(jobSettings.Name, JobTypes.GetJobType(jobSettings)); if (existingJob == null) { return(HttpStatusCode.NotFound); } //delete and return repo.DeleteJob(jobSettings); return(jobSettings); }
public void DeleteJob(IJobSettings job) { _logger.Info($"Deleting job {JobTypes.GetJobType(job)}.{job.Name}"); _scheduler.DeleteJob(new JobKey(job.Name, JobTypes.GetJobType(job))); }
public void DeleteJob() { _scheduler.DeleteJob(new JobKey(_preChangeName, JobTypes.GetJobType(Job))); }