public static List <IJobDetail> GetJobDetail(string JobName = "", string TriggerName = "", string JobGroup = "", string TriggerGroup = "") { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); var jobs = from j in quartz.GetJobs() where (string.IsNullOrEmpty(JobName) || j.Key.Name == JobName) && (string.IsNullOrEmpty(JobGroup) || j.Key.Group == JobGroup) select j; List <IJobDetail> jobsfound = new List <IJobDetail>(); if (!string.IsNullOrEmpty(TriggerGroup) || !string.IsNullOrEmpty(TriggerName)) { foreach (IJobDetail job in jobs) { if (quartz.Scheduler.GetTriggersOfJob(job.Key).Result.Where(t => (string.IsNullOrEmpty(TriggerName) || t.Key.Name == TriggerName) && (string.IsNullOrEmpty(TriggerGroup) || t.Key.Group == TriggerGroup)).Any()) { jobsfound.Add(job); } } } else { jobsfound = jobs.ToList(); } var response = jobsfound; quartz.Scheduler = null; quartz = null; return(response); }
public static void PauseTriggers(string JobName = "", string TriggerName = "", string JobGroup = "", string TriggerGroup = "") { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); List <IJobDetail> Jobs = GetJobDetail(JobName, JobGroup); Jobs.ForEach(j => GetJobTriggers(j.Key).Where(t => (string.IsNullOrEmpty(TriggerName) || t.Key.Name == TriggerName) && (string.IsNullOrEmpty(TriggerGroup) || t.Key.Group == TriggerGroup)).ToList().ForEach(t => quartz.Scheduler.PauseTrigger(t.Key).GetAwaiter().GetResult())); quartz.Scheduler = null; quartz = null; }
public static List <ITrigger> GetJobTriggers(JobKey jobkey) { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); var response = quartz.Scheduler.GetTriggersOfJob(jobkey).GetAwaiter().GetResult().ToList(); quartz.Scheduler = null; quartz = null; return(response); }
public static void AddJobDetailsFromTypes(Type[] types, bool Replace) { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); quartz.AddJobDetails(quartz.GetJobsFromTypes(types), Replace); quartz.Scheduler = null; quartz = null; }
public static List <IJobDetail> GetJobDetail(string JobName = "", string TriggerName = "", string JobGroup = "", string TriggerGroup = "") { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); var jobs = from j in quartz.GetJobs() where (string.IsNullOrEmpty(JobName) || j.Key.Name == JobName) && (string.IsNullOrEmpty(JobGroup) || j.Key.Group == JobGroup) select j; var response = jobs.ToList(); quartz.Scheduler = null; quartz = null; return(response); }
public static ITrigger ScheduleCustomJobTypeWithCronExpression(Type jobType, string JobName, string JobGroup, string TriggerName, string TriggerGroup, string CronExpression, IDictionary JobData, bool UseReflectionJobType) { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); ITrigger Schedule = TriggerBuilder.Create().WithCronSchedule(CronExpression).WithIdentity(TriggerName, TriggerGroup).Build(); JobDataMap map = new JobDataMap(JobData); if (UseReflectionJobType) { return(quartz.ScheduleCustomReflectionJob(jobType, JobName, JobGroup, map, Schedule)); } return(quartz.ScheduleCustomJob(jobType, JobName, JobGroup, map, Schedule)); }
public static void AddJobData(string JobName, string Key, object Value, string JobGroup = "") { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); List <IJobDetail> Jobs = GetJobDetail(JobName, JobGroup); Jobs.ForEach(j => { j.JobDataMap[Key] = Value; if (j.JobDataMap[Key] == null) { j.JobDataMap.Put(Key, Value); quartz.Scheduler.AddJob(j, false, true).GetAwaiter().GetResult();; } }); quartz.Scheduler = null; quartz = null; }
public void BackupQuartzJobDetails(string Path) { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); IReadOnlyList <IQuartzServiceJob> jobs = quartz.GetJobsFromTypes(GetJobTypes()); List <IJobDetail> JobDetails = new List <IJobDetail>(); foreach (IJobDetail d in quartz.GetJobs()) { JobDetails.Add(d); } string Json = JsonConvert.SerializeObject(JobDetails); File.WriteAllText(Path, Json); }
public static List <ITrigger> RunJobNow(string JobName, string JobGroup = "", string TriggerName = "", string TriggerGroup = "") { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); List <ITrigger> TriggerList = new List <ITrigger>(); List <IJobDetail> Jobs = GetJobDetail(JobName, JobGroup); Jobs.ForEach(j => { ITrigger t = TriggerBuilder.Create().WithIdentity(string.IsNullOrEmpty(TriggerName)?j.Key.Name + "Now":TriggerName, string.IsNullOrEmpty(TriggerGroup)?j.Key.Group:TriggerGroup).StartNow().Build(); TriggerList.Add(t); quartz.Scheduler.ScheduleJob(j, t).GetAwaiter().GetResult(); }); quartz.Scheduler = null; quartz = null; return(TriggerList); }
public static List <ITrigger> RunJobWithCronExpression(string JobName, string CronExpression, string TriggerName, string JobGroup = "", bool ReplaceExisting = true) { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); List <ITrigger> TriggerList = new List <ITrigger>(); List <IJobDetail> Jobs = GetJobDetail(JobName, JobGroup); Jobs.ForEach(j => { ITrigger t = TriggerBuilder.Create().WithSchedule(CronScheduleBuilder.CronSchedule(CronExpression).WithMisfireHandlingInstructionFireAndProceed()).WithIdentity(TriggerName, JobName).Build(); TriggerList.Add(t); quartz.Scheduler.ScheduleJob(j, new ITrigger[] { t }, ReplaceExisting).GetAwaiter().GetResult(); }); quartz.Scheduler = null; quartz = null; return(TriggerList); }
protected static void Start(string[] args) { try { quartz = new QuartzWrapper(new QuartzJobStoreSettings(true).GetQuartzSettings()); quartz.StartQuartz(); if (!quartzJobStoreSettings.UseSqlServerQuartz) { ScheduleJobTypes(GetJobTypes()); } } catch (Exception ex) { _log.Error(ex); throw ex; } }
protected static void Start(string[] args) { try { var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config")); _log.Info("Starting"); quartz = new QuartzWrapper(new QuartzJobStoreSettings(true).GetQuartzSettings()); quartz.StartQuartz(); if (!quartzJobStoreSettings.UseSqlServerQuartz) { ScheduleJobTypes(GetJobTypes()); } } catch (Exception ex) { _log.Error(ex); throw ex; } }
public void UpdateQuartzJobData() { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); IReadOnlyList <IQuartzServiceJob> jobs = quartz.GetJobsFromTypes(GetJobTypes()); foreach (IQuartzServiceJob job in jobs) { IJobDetail d = job.JobDetail.Build(); IJobDetail d2 = quartz.Scheduler.GetJobDetail(d.Key).Result; bool DoUpdate = false; if (d2 != null) { foreach (string Key in d.JobDataMap.Keys) { d2.JobDataMap[Key] = d.JobDataMap[Key]; DoUpdate = true; } if (DoUpdate) { quartz.Scheduler.AddJob(d2, true).GetAwaiter().GetResult(); } } } }
public static void ScheduleJobTypes(Type[] types) { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); quartz.ScheduleJobTypes(quartz.GetJobsFromTypes(types)); }
public static void ScheduleReflectionJobTypes(Type[] types) { QuartzWrapper quartz = new QuartzWrapper(quartzJobStoreSettings.GetQuartzSettings()); quartz.ScheduleReflectionJobTypes(types); }