public async Task <JobInfoModel[]> listJobs() { var allJobKeys = await _schedularService.scheduler.GetJobKeys(GroupMatcher <JobKey> .AnyGroup()); return(await Task.WhenAll(allJobKeys.Select(tKey => JobInfoModel.fromJobKey(_schedularService.scheduler, tKey)))); }
public async Task <JobInfoModel> GetJobStatusAsync(string jobName) { var allJobs = await scheduler.GetJobKeys(GroupMatcher <JobKey> .AnyGroup()); var theJob = allJobs.Where(j => j.Name == jobName).FirstOrDefault(); if (null == theJob) { throw new FileNotFoundException($"the job {jobName} not found"); } return(await JobInfoModel.fromJobKey(scheduler, theJob)); }
public async Task <JobInfoModel> RunNowAsync(string jobName, IDictionary <string, object> instanceDataMap = null, bool blockTillComplete = false, TimeSpan?timeout = null ) { var jobTnfo = await GetJobStatusAsync(jobName); _logger.LogDebug($"runNow needed runningStatus-> {jobTnfo.isRunning}"); if (jobTnfo.isRunning) { var ex = new Exception("Job is already running"); _logger.LogCritical(ex, "Job is already running"); throw ex; } var myInstanceMap = new Dictionary <string, Object>(instanceDataMap); myInstanceMap[JobInfoModel.INTANCE_GUID_NAME] = Guid.NewGuid(); var taskWaiter = blockTillComplete ? _jobListener.getJobWaiter((Guid)myInstanceMap[JobInfoModel.INTANCE_GUID_NAME]) : null; await scheduler.TriggerJob(jobTnfo.jobKey, new JobDataMap(myInstanceMap as IDictionary <string, object>)); if (blockTillComplete) { var done = await Task.WhenAny(taskWaiter, Task.Delay(-1, new CancellationTokenSource(timeout ?? TimeSpan.FromMinutes(15)).Token)); if (done.IsFaulted) { throw done.Exception.InnerException ?? done.Exception; } } else { //give the job a min to Start await Task.Delay(TimeSpan.FromSeconds(5)); } //reload triggers jobTnfo = await JobInfoModel.fromJobKey(scheduler, jobTnfo.jobKey); return(jobTnfo); }