public async Task <List <QuartzInfoDTO> > GetAllTriggersByProjectId(string projectId) { List <QuartzInfoDTO> infos = new List <QuartzInfoDTO>(); var groupMatcher = GroupMatcher <TriggerKey> .GroupContains(projectId); var triggerKeysFromGroup = await _scheduler.GetTriggerKeys(groupMatcher); foreach (var triggerKey in triggerKeysFromGroup) { var trigger = await _scheduler.GetTrigger(triggerKey); QuartzInfoDTO info = new QuartzInfoDTO() { Id = trigger.Key.Name, // same as triggerId Group = trigger.Key.Group, // same as projectId Description = trigger.Description, CronExpression = (trigger is ICronTrigger cronTrigger) ? cronTrigger.CronExpressionString : "", NextFireTime = trigger.GetNextFireTimeUtc().GetValueOrDefault().LocalDateTime, PreviousFireTime = trigger.GetPreviousFireTimeUtc().GetValueOrDefault().LocalDateTime }; infos.Add(info); } return(infos); }
/// <summary> /// Stops the scheduled job service. /// </summary> public void Stop() { _scheduler .PauseAll() .ConfigureAwait(false) .GetAwaiter() .GetResult(); foreach (var group in _scheduler.GetJobGroupNames().Result) { foreach (var key in _scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupContains(group)).Result) { var jobDetail = _scheduler.GetJobDetail(key).Result; Log.Debug("-- Shutdown Job: '{0}', class={1}", jobDetail.Key, jobDetail.JobType); var job = (IScheduledJob)Activator.CreateInstance(jobDetail.JobType); job.Shutdown(); } } _scheduler .Shutdown() .ConfigureAwait(false) .GetAwaiter() .GetResult(); }
public async Task <IEnumerable <JobInfoViewModel> > GetJobsDetailsForPlayer(TravianUser player) { var groupName = SchedulerService.BuildGroupKey(player.UserName, player.BotUserName); var matcher = GroupMatcher <JobKey> .GroupContains(groupName); var result = new List <JobInfoViewModel>(); foreach (var key in await _scheduler.GetJobKeys(matcher)) { var triggers = await _scheduler.GetTriggersOfJob(key); var detail = await _scheduler.GetJobDetail(key); var nextTime = triggers.FirstOrDefault()?.GetNextFireTimeUtc(); if (!nextTime.HasValue) { var cmd = detail.JobDataMap[AbstractJob.JobExecutionDataKey] as IQueueableCommand; nextTime = cmd.Start; } result.Add(new JobInfoViewModel { Name = key.Name, Group = key.Group, NextExecutionTime = nextTime.Value.ToDisplayStringApplyTimeZone(player.PlayerData.TimeZone) }); } return(result); }
public static async Task WriteJobInfo() { string filePath = HttpContext.Current.Server.MapPath("~/AppLogs.txt"); IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler(); var jobGroupNames = await scheduler.GetJobGroupNames(); if (jobGroupNames.Count <= 0) { await Log.WriteTextAsync(filePath, "Job(s) scheduled count: " + jobGroupNames.Count.ToString()); } else { foreach (var group in jobGroupNames) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); var jobKeys = await scheduler.GetJobKeys(groupMatcher); await Log.WriteTextAsync(filePath, "Job(s) scheduled count: " + jobKeys.Count.ToString()); foreach (var jobKey in jobKeys) { var detail = scheduler.GetJobDetail(jobKey); var triggers = await scheduler.GetTriggersOfJob(jobKey); foreach (var trigger in triggers) { await Log.WriteTextAsync(filePath, string.Format("Group: {0}, Job name: {1}, State: {2}, Next Fire Time: {3}", group, jobKey.Name, scheduler.GetTriggerState(trigger.Key).Result.ToString(), trigger.GetNextFireTimeUtc().Value.LocalDateTime.ToString("dd/MM/yyyy HH:mm:ss"))); } } } } }
public async Task <Dictionary <IJobDetail, DateTimeOffset> > GetRunningJobsList() { var result = new Dictionary <IJobDetail, DateTimeOffset>(); var groups = await _scheduler.GetJobGroupNames(); foreach (var group in groups) { var matcher = GroupMatcher <JobKey> .GroupContains(group); foreach (var key in await _scheduler.GetJobKeys(matcher)) { var triggers = await _scheduler.GetTriggersOfJob(key); var detail = await _scheduler.GetJobDetail(key); var nextTime = triggers.FirstOrDefault()?.GetNextFireTimeUtc(); if (!nextTime.HasValue) { var cmd = detail.JobDataMap[AbstractJob.JobExecutionDataKey] as IQueueableCommand; nextTime = cmd?.Start; } result.Add(detail, nextTime ?? DateTimeOffset.MinValue); } } return(result); }
public async Task <List <JobKeyWithDescription> > GetJobKeysWithDescription(string groupName) { var jobKeys = await _scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupContains(groupName)); var jobKeysWithDescription = new List <JobKeyWithDescription>(); foreach (var jobKey in jobKeys) { var jobDetail = await _scheduler.GetJobDetail(jobKey); var triggers = await _scheduler.GetTriggersOfJob(jobKey); jobKeysWithDescription.Add( new JobKeyWithDescription { JobName = jobKey.Name, JobGroup = jobKey.Group, Description = jobDetail.Description, RequestRecovery = jobDetail.RequestsRecovery, IsDurable = jobDetail.Durable, Triggers = _mapper.Map <List <ITrigger>, List <TriggerKeyWithDescription> >(triggers.ToList()) }); } return(jobKeysWithDescription); }
private static IList <JobInfo> GetAllJobs(IScheduler scheduler) { IList <string> jobGroups = scheduler.GetJobGroupNames(); IList <JobInfo> jobsList = new List <JobInfo>(); foreach (string group in jobGroups) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); var jobKeys = scheduler.GetJobKeys(groupMatcher); foreach (var jobKey in jobKeys) { var detail = scheduler.GetJobDetail(jobKey); var triggers = scheduler.GetTriggersOfJob(jobKey); foreach (ITrigger trigger in triggers) { DateTimeOffset?nextFireTime = trigger.GetNextFireTimeUtc(); DateTimeOffset?previousFireTime = trigger.GetPreviousFireTimeUtc(); jobsList.Add(new JobInfo { GropName = group, Name = jobKey.Name, Description = detail.Description, TriggerName = trigger.Key.Name, TriggerGroup = trigger.Key.Group, TriggerTypeName = trigger.GetType().Name, TriggerStage = scheduler.GetTriggerState(trigger.Key).ToString(), NextFireTime = nextFireTime, PrevFireTime = previousFireTime }); } } } return(jobsList); }
public async Task <IEnumerable <object> > GetUpcomingJobs() { var list = new List <object>(); var jobGroups = await _scheduler.GetJobGroupNames(); foreach (string group in jobGroups) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); var jobKeys = await _scheduler.GetJobKeys(groupMatcher); foreach (var jobKey in jobKeys) { var detail = await _scheduler.GetJobDetail(jobKey); var triggers = await _scheduler.GetTriggersOfJob(jobKey); list.Add(new { Detail = detail, Triggers = triggers }); } } return(list); }
/// <summary> /// Get job details of type <see cref="jobType"/>. /// Get all the job details if <see cref="jobType"/> is not specified /// </summary> /// <param name="jobType"></param> /// <returns></returns> public IEnumerable <IJobDetail> GetJobDetails(Type jobType = null) { IList <IJobDetail> jobDetails = new List <IJobDetail>(); IList <string> jobGroups = _scheduler.GetJobGroupNames(); foreach (string group in jobGroups) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); var jobKeys = _scheduler.GetJobKeys(groupMatcher); foreach (var jobKey in jobKeys) { var detail = _scheduler.GetJobDetail(jobKey); if (null == jobType) { jobDetails.Add(detail); } else { if (jobType == detail.JobType) { jobDetails.Add(detail); } } } } return(jobDetails); }
/// <summary> /// 打印所有Job信息 /// </summary> public static async Task <string> PrintAllJobsInfo() { string content = "当前任务列表:"; IReadOnlyCollection <string> jobGroups = await sched.GetJobGroupNames(); foreach (string group in jobGroups) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); var jobKeys = await sched.GetJobKeys(groupMatcher); foreach (var jobKey in jobKeys) { var detail = await sched.GetJobDetail(jobKey); var triggers = await sched.GetTriggersOfJob(jobKey); foreach (ITrigger trigger in triggers) { content += "\n 任务名称:" + jobKey.Name; DateTimeOffset?nextFireTime = trigger.GetNextFireTimeUtc(); if (nextFireTime.HasValue) { content += ",下次执行时间:" + nextFireTime.Value.LocalDateTime.ToString(); } } } } Console.WriteLine(content); return(content); }
/// <summary> /// /// </summary> /// <param name="groupsToDisable"></param> /// <returns></returns> private bool DisableJobsByGroup(string[] groupsToDisable) { IList <string> jobGroups = this.scheduler.GetJobGroupNames(); bool jobsDeleted = false; List <TriggerKey> listaTriggers = new List <TriggerKey>(); foreach (string group in groupsToDisable) { var groupMatcher = GroupMatcher <TriggerKey> .GroupContains(group); var triggerKeys = this.scheduler.GetTriggerKeys(groupMatcher); foreach (TriggerKey item in triggerKeys) { if (this.scheduler.CheckExists(item)) { listaTriggers.Add(item); } } } if (listaTriggers.Any()) { jobsDeleted = this.scheduler.UnscheduleJobs(listaTriggers); } else { jobsDeleted = true; } return(jobsDeleted); }
/// <summary> /// Método que remueve los jobs por grupo /// </summary> /// <param name="groupsToRemove"></param> private bool RemoveJobsByGroup(string[] groupsToRemove) { IList <string> jobGroups = scheduler.GetJobGroupNames(); bool jobsDeleted = false; List <JobKey> listaTrabajos = new List <JobKey>(); foreach (string group in groupsToRemove) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); var jobKeys = this.scheduler.GetJobKeys(groupMatcher); foreach (JobKey item in jobKeys) { if (scheduler.CheckExists(item)) { listaTrabajos.Add(item); } } } if (listaTrabajos.Any()) { jobsDeleted = this.scheduler.DeleteJobs(listaTrabajos); } else { jobsDeleted = true; } return(jobsDeleted); }
/* This method returns a list of billpayID's of jobs which have the * state of normal and exclude the jobs which are in a paused state * */ public List <int> GetAllActiveJobs() { List <int> ListOfActiveJobs = new List <int>(); //Returns a list of job keys associated with the job group "JobGroup1" //var groupMatcher = GroupMatcher<JobKey>.GroupContains("JobGroup1"); //Get the keys of all of the Job s that have the given group name. //var jobKeys = sched.GetJobKeys(groupMatcher); var SetOfTriggerKeys = sched.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupContains("TriggerGrp1")); //Examine every job trigger to check what is the state of it //Note: Each trigger has the billpayID as its name foreach (var trigger in SetOfTriggerKeys) { if (sched.GetTriggerState(trigger) == TriggerState.Normal) { Debug.WriteLine("Trigger Name: " + trigger.Name + " State is NORMAL"); ListOfActiveJobs.Add(Convert.ToInt32(trigger.Name)); } } return(ListOfActiveJobs); }
private async Task <dynamic> GetJobs(dynamic parameters, CancellationToken token) { var groupNames = _scheduler.GetJobGroupNames(); // getting all jobs with group information var quartzJobdetails = groupNames .AsParallel() .SelectMany(gn => { var groupMatcher = GroupMatcher <JobKey> .GroupContains(gn); var jobKeys = _scheduler.GetJobKeys(groupMatcher); return(jobKeys.Select(_scheduler.GetJobDetail)); }) .ToList(); // map to view model var jobDetails = quartzJobdetails .Select(jb => new JobDetail { JobName = jb.Key.Name, JobGroup = jb.Key.Group, Description = jb.Description, JobType = jb.JobType, JobDataMap = jb.JobDataMap, Durable = jb.Durable }) .ToList(); return(Negotiate .WithView("jobs") .WithModel(jobDetails)); }
public IEnumerable <Job> GetJobs() { try { var jobs = new List <Job>(); IList <string> jobGroups = _scheduler.GetJobGroupNames(); foreach (string group in jobGroups) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); var jobKeys = _scheduler.GetJobKeys(groupMatcher); foreach (var jobKey in jobKeys) { var jobDetail = _scheduler.GetJobDetail(jobKey); var dataMap = jobDetail.JobDataMap; var jobContext = GetContextFromJobDataMap(jobKey.Name, dataMap); jobs.Add(jobContext); } } return(jobs); } catch (Exception ex) { throw new ApplicationException(string.Format("There was an error retrieving the job detail"), ex); } }
private void ScheduleJob(ISwJob job) { var groupToResume = _scheduler.GetJobGroupNames(); foreach (var group in groupToResume) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); var jobKeys = _scheduler.GetJobKeys(groupMatcher); foreach (var jobKey in jobKeys) { var detail = _scheduler.GetJobDetail(jobKey); if (detail.JobType != job.GetType()) { continue; } var triggers = _scheduler.GetTriggersOfJob(jobKey); foreach (ITrigger triggerResume in triggers) { if (_scheduler.GetTriggerState(triggerResume.Key) != TriggerState.Paused) { continue; } _scheduler.ResumeTrigger(triggerResume.Key); _scheduler.ResumeJob(detail.Key); } } } }
private void UpdateButtons(TreeViewEventArgs e) { CmdDelete.Enabled = e.Node is TriggerNode || e.Node is JobNode || e.Node is CalendarNode; CmdAdd.Enabled = e.Node is SchedulerNode || e.Node is JobGroupsNode || e.Node is JobGroupNode || e.Node is JobNode || e.Node is TriggerNode || e.Node is CalendarsNode; CmdEdit.Enabled = e.Node is TriggerNode; CmdRunJobNow.Enabled = e.Node is JobNode; CmdPause.Enabled = e.Node is TriggerNode; // check if there are any calendars if (e.Node is TriggerNode) { CmdAdd.Enabled = mScheduler.GetCalendarNames().Any(); } // trying to delete calendar from top level calendars node if (e.Node is CalendarNode && e.Node.Parent is CalendarsNode) { // cannot delete a calendar if it is referenced by a trigger var triggerMatcher = GroupMatcher <TriggerKey> .GroupContains(""); var calNode = (CalendarNode)e.Node; var refTriggers = mScheduler.GetTriggerKeys(triggerMatcher).Where(x => mScheduler.GetTrigger(x).CalendarName == calNode.Name); CmdDelete.Enabled = !refTriggers.Any(); } }
public void ResumeTrigger_UseContainsOperator_Successfully() { //arrange var job = CreateJob(); var trigger1 = CreateTrigger("trigger1", "triggerGroup", job.Key); var trigger2 = CreateTrigger("trigger2", "triggerGroup", job.Key); var trigger3 = CreateTrigger("trigger3", "triggerfoobarGroup", job.Key); var trigger4 = CreateTrigger("trigger4", "triggerfoobarGroup", job.Key); JobStore.StoreJob(job, true); JobStore.StoreTrigger(trigger1, true); JobStore.StoreTrigger(trigger2, true); JobStore.StoreTrigger(trigger3, true); JobStore.StoreTrigger(trigger4, true); JobStore.PauseTriggers(GroupMatcher <TriggerKey> .GroupContains("foobar")); //act var resumedGroups = JobStore.ResumeTriggers(GroupMatcher <TriggerKey> .GroupContains("foobar")).Result; //assert Assert.IsTrue(resumedGroups.Count == 1); Assert.AreEqual(TriggerState.Normal, JobStore.GetTriggerState(trigger3.Key).Result); Assert.AreEqual(TriggerState.Normal, JobStore.GetTriggerState(trigger4.Key).Result); }
/// <summary> /// Removes a single job from scheduler by JobID /// </summary> /// <param name="jobID">Job ID to be removed</param> public void removeJobFromScheduler(String jobID) { IList <string> jobGroups = scheduler.GetJobGroupNames(); var groupMatcher = GroupMatcher <JobKey> .GroupContains(jobGroups[0]); var jobKeys = scheduler.GetJobKeys(groupMatcher); foreach (JobKey jobKey in jobKeys) { var detail = scheduler.GetJobDetail(jobKey); String strID = detail.JobDataMap.GetString("ID"); if (strID == jobID) { try { scheduler.DeleteJob(jobKey); QuartzService.log("Job ID " + jobID + " has been unscheduled"); } catch (Exception ex) { QuartzService.log("Error removing job " + jobID + " from scheduler \n" + ex); } break; } } }
private void addJobNodes(TreeNode node) { string group = node.Parent.Text; var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); QuartzScheduler scheduler = getScheduler(node); var jobKeys = scheduler.GetScheduler().GetJobKeys(groupMatcher); foreach (var jobKey in jobKeys) { try { IJobDetail detail = scheduler.GetScheduler().GetJobDetail(jobKey); JobNode jobNode = new JobNode(detail); node.Nodes.Add(jobNode); addTriggerNodes(jobNode); } catch (Exception ex) { node.Nodes.Add(string.Format("Unknown Job Type ({0})", jobKey.Name)); //TODO: Do something useful with this exception. Most likely cause is the client does not have a copy of a given dll and can't load the type. _Log.Error("Error loading jobs.", ex); } } }
public async Task <object> GetJob() { IScheduler scheduler = await StdSchedulerFactory.GetDefaultScheduler(); var groupNames = await scheduler.GetJobGroupNames(); //List<IReadOnlyCollection<JobKey>> ListJobKeys = new List<IReadOnlyCollection<JobKey>>(); List <object> result = new List <object>(); foreach (var group in groupNames) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); var jobKeys = await scheduler.GetJobKeys(groupMatcher); //ListJobKeys.Add(jobKeys); foreach (var jobKey in jobKeys) { var detail = await scheduler.GetJobDetail(jobKey); var triggers = await scheduler.GetTriggersOfJob(jobKey); foreach (ITrigger trigger in triggers) { DateTimeOffset?nextFireTime = trigger.GetNextFireTimeUtc(); DateTimeOffset?previousFireTime = trigger.GetPreviousFireTimeUtc(); result.Add(new { Group = group, JobKeyName = jobKey.Name, Description = detail.Description, TriggerKeyName = trigger.Key.Name, TriggerKeyGroup = trigger.Key.Group, TriggerState = scheduler.GetTriggerState(trigger.Key), NextFireTime = nextFireTime == null ? null : nextFireTime.Value.LocalDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff"), PreviousFireTime = previousFireTime == null ? null : previousFireTime.Value.LocalDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff") }); } } } return(Json(result, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Gets the jobs. /// </summary> /// <returns></returns> public DataTable GetJobs() { DataTable table; try { table = new DataTable(); table.Columns.Add("JobName"); table.Columns.Add("JobGroup"); table.Columns.Add("JobDescription"); table.Columns.Add("JobType"); table.Columns.Add("JobStatus"); table.Columns.Add("NextFireTime"); table.Columns.Add("PreviousFireTime"); table.Columns.Add("Instance"); var jobGroups = GetScheduler().GetJobGroupNames().Result; foreach (var group in jobGroups) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); var jobKeys = GetScheduler().GetJobKeys(groupMatcher).Result; foreach (var jobKey in jobKeys) { var detail = GetScheduler().GetJobDetail(jobKey).Result; var row = table.NewRow(); row["JobGroup"] = group; row["JobName"] = jobKey.Name; row["JobDescription"] = detail.Description; row["JobType"] = detail.JobType.Name; row["Instance"] = detail.JobDataMap["AosUri"]; var triggers = GetScheduler().GetTriggersOfJob(jobKey).Result; if (triggers.Count > 0) { var nextFireTime = triggers.First().GetNextFireTimeUtc(); if (nextFireTime.HasValue) { row["NextFireTime"] = TimeZone.CurrentTimeZone.ToLocalTime(nextFireTime.Value.DateTime); } var previousFireTime = triggers.First().GetPreviousFireTimeUtc(); if (previousFireTime.HasValue) { row["PreviousFireTime"] = TimeZone.CurrentTimeZone.ToLocalTime(previousFireTime.Value.DateTime); } row["JobStatus"] = GetScheduler().GetTriggerState(triggers.First().Key).Result.ToString(); } table.Rows.Add(row); } } } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.Unexpected_error); table = null; } return(table); }
public async Task <IActionResult> GetBackupFolders(int remoteId) { using (var context = _contextFactory.CreateContext()) { var folders = await context.BackupFolders.AsNoTracking().Where(f => f.BackupRemoteId == remoteId).ToListAsync(); var returnList = new List <object>(); foreach (var backupFolder in folders) { var keys = await _scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupContains(DiscoverFilesJob.JobGroupName)); var nextTrigger = keys.SelectMany(x => _scheduler.GetTriggersOfJob(x).Result).OrderBy(x => x.GetNextFireTimeUtc()).FirstOrDefault(); var nextFireTime = nextTrigger?.GetNextFireTimeUtc()?.ToLocalTime().ToString("g"); var trackedFilesQuery = context.TrackedFiles.Where(f => f.BackupFolderId == backupFolder.BackupFolderId); returnList.Add(new { backupFolder.BackupFolderId, backupFolder.BackupRemoteId, backupFolder.Name, Size = trackedFilesQuery.Sum(f => f.SizeBytes), NumFiles = trackedFilesQuery.Count(), LastSync = backupFolder.LastSync?.ToLocalTime().ToString("g"), NextFireTime = nextFireTime }); } return(Ok(returnList)); } }
public List <Job> GetJobs() { List <Job> loList = new List <Job>(); Job loJob; if (this.moScheduler != null) { foreach (string lsGroup in this.moScheduler.GetJobGroupNames()) { var loGroupMatcher = GroupMatcher <JobKey> .GroupContains(lsGroup); foreach (var loJobKey in this.moScheduler.GetJobKeys(loGroupMatcher)) { var loJobDetail = this.moScheduler.GetJobDetail(loJobKey); loJob = new Job() { Name = loJobKey.Name, Group = lsGroup, Description = loJobDetail.Description, TypeName = loJobDetail.JobType.FullName, AssemblyName = Path.GetFileName(loJobDetail.JobType.Assembly.Location) }; this.moScheduler.GetTriggersOfJob(loJobKey).ToList().ForEach(item => loJob.TriggerList.Add(this.CreateTrigger(item))); loList.Add(loJob); } } } return(loList); }
public async Task Execute(IJobExecutionContext context) { var scheduler = context.Scheduler; var jobGroupNames = await scheduler.GetJobGroupNames(); foreach (var jobGroupName in jobGroupNames) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(jobGroupName); var jobKeys = await scheduler.GetJobKeys(groupMatcher); foreach (var jobKey in jobKeys) { var triggers = await scheduler.GetTriggersOfJob(jobKey); foreach (ITrigger trigger in triggers) { _logger.Info( $"Previous trigger for scheduled Job {jobKey.Name} was last executed at {trigger.GetPreviousFireTimeUtc()}"); _logger.Info( $"Next trigger for scheduled Job {jobKey.Name} is scheduled for {trigger.GetNextFireTimeUtc()}"); } } } }
public List <JobDescription> Stop() { List <JobDescription> list = new List <JobDescription>(); var jobGroups = scheduler.GetJobGroupNames().Result; foreach (string group in jobGroups) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); var jobKeys = scheduler.GetJobKeys(groupMatcher).Result; foreach (var jobKey in jobKeys) { var detail = scheduler.GetJobDetail(jobKey).Result; var triggers = scheduler.GetTriggersOfJob(jobKey).Result; foreach (ITrigger trigger in triggers) { list.Add(new JobDescription() { Group = group, Name = jobKey.Name, Description = detail.Description, TriggerName = trigger.Key.Name, TriggerType = trigger.GetType().Name, TriggerState = scheduler.GetTriggerState(trigger.Key).Result, NextFireTime = trigger.GetNextFireTimeUtc(), PreviousFireTime = trigger.GetPreviousFireTimeUtc(), }); } } } return(list); }
private void GetJobs() { var scheduler = StdSchedulerFactory.GetDefaultScheduler(); IReadOnlyCollection <string> jobGroups = scheduler.Result.GetJobGroupNames().Result; foreach (string group in jobGroups) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(group); var jobKeys = scheduler.Result.GetJobKeys(groupMatcher).Result; foreach (var jobKey in jobKeys) { var detail = scheduler.Result.GetJobDetail(jobKey).Result; var triggers = scheduler.Result.GetTriggersOfJob(jobKey).Result; foreach (ITrigger trigger in triggers) { var newJob = new QuartzJobDetail(); newJob.Group = group; newJob.JobName = detail.JobDataMap.Get(SitecronConstants.ParamNames.Name).ToString(); newJob.Type = detail.JobType.ToString(); newJob.State = scheduler.Result.GetTriggerState(trigger.Key).Result.ToString(); DateTimeOffset?nextFireTime = trigger.GetNextFireTimeUtc(); if (nextFireTime.HasValue) { newJob.NextFireTimeUtc = nextFireTime.Value.LocalDateTime.ToString(); } QuartzJobs.Add(newJob); } } } }
/// <summary> /// 删除指定分组的Jobs /// </summary> /// <param name="group">Job分组名称</param> /// <param name="compareWith">分组名称匹配规则</param> /// <returns>true if all of the Jobs were found and deleted, false if one or more were not</returns> public static async Task <bool> DeleteJobsAsync(string group, StringOperator compareWith) { GroupMatcher <JobKey> matcher; if (Equals(compareWith, StringOperator.Contains)) { matcher = GroupMatcher <JobKey> .GroupContains(group); } else if (Equals(compareWith, StringOperator.EndsWith)) { matcher = GroupMatcher <JobKey> .GroupEndsWith(group); } else if (Equals(compareWith, StringOperator.Equality)) { matcher = GroupMatcher <JobKey> .GroupEquals(group); } else if (Equals(compareWith, StringOperator.StartsWith)) { matcher = GroupMatcher <JobKey> .GroupStartsWith(group); } else { matcher = GroupMatcher <JobKey> .AnyGroup(); } return(await GetScheduler().DeleteJobs((await GetScheduler().GetJobKeys(matcher)).ToList())); }
private static void ConfigureJobs() { if (_scheduler == null) { return; } RegisterJob <PostalCodeJobDataConfiguration, PostalCodesJob>(); RegisterJob <MunicipalityCodeJobDataConfiguration, MunicipalityCodesJob>(); RegisterJob <AreaCodeJobDataConfiguration, ProvinceCodesJob>(); RegisterJob <AreaCodeJobDataConfiguration, HospitalRegionCodesJob>(); RegisterJob <AreaCodeJobDataConfiguration, BusinessRegionCodesJob>(); RegisterJob <FintoDataJobDataConfiguration, LifeEventsFintoJob>(); RegisterJob <FintoDataJobDataConfiguration, ServiceClassesFintoJob>(); RegisterJob <FintoDataJobDataConfiguration, TargetGroupsFintoJob>(); RegisterJob <FintoDataJobDataConfiguration, OntologyTermsFintoJob>(); var scheduledTriggerKeys = _scheduledTriggers.Values.Select(t => t.Key); var trigersToRemove = _scheduler.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupContains(PTV_JOB_GROUP)).Result .Where(triggerKey => !scheduledTriggerKeys.Contains(triggerKey)) .ToList(); _scheduler.UnscheduleJobs(trigersToRemove).Wait(); var scheduledJobKeys = _scheduledTriggers.Values.Select(t => t.JobKey); var jobsToRemove = _scheduler.GetJobKeys(GroupMatcher <JobKey> .GroupContains(PTV_JOB_GROUP)).Result .Where(jobKey => !scheduledJobKeys.Contains(jobKey)) .ToList(); _scheduler.DeleteJobs(jobsToRemove).Wait(); }
public async Task DeleteAllSheduleJob(string projectId) { var groupMatcher = GroupMatcher <JobKey> .GroupContains(projectId); var jobKeys = await _scheduler.GetJobKeys(groupMatcher); await _scheduler.DeleteJobs(jobKeys); }