public Task Execute(IJobExecutionContext context) { return(Task.Run(() => { (context.Get("Action") as Action)?.Invoke(); })); }
public static void AppendToOutputBuffer(this IJobExecutionContext context, string message) { var contents = context.Get(Constants.FieldNames.StandardOutput); contents += message; contents += Environment.NewLine; context.Put(Constants.FieldNames.StandardOutput, contents); }
/// <summary> /// 写执行日志到数据库 /// </summary> /// <param name="context"></param> protected void WirteScheduleLog(IJobExecutionContext context) { string _result = string.Format("【{0}】执行完毕,执行结果:{1}", this.JobName, context.Get(this.ExecResult) != null ? context.Get(this.ExecResult).ToString() : "失败"); Log4.Info(_result); if (jobDetail != null) { schedulebll.SaveScheduleLog(new ScheduleJob_Log { description = string.Format("【{0}】执行完毕,执行结果:{1}", jobDetail.description, context.Get(this.ExecResult) != null ? context.Get(this.ExecResult).ToString() : "失败"), job_name = jobDetail.job_name, sched_name = jobDetail.sched_name, update_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), success = (context.Get(this.ExecResult) != null && context.Get(this.ExecResult).ToString() == "成功" ? true : false) }); } }
public Task Execute(IJobExecutionContext context) { JobEvent ev = new JobEvent() { JsonData = (string)context.Get(JobNames.JobData) }; // Launch event to azure with json data return(Task.CompletedTask); }
public static object SafeGet(this IJobExecutionContext executionContext, string key) { try { return(executionContext.Get(key)); } catch { //No big deal, just swallow and continue return(null); } }
public virtual void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException) { //轮询调度任务不写日志 if (context.JobDetail.JobType.Name == "Job_Scheduler") { return; } var jobName = context.JobDetail.JobDataMap["jobName"]; if (jobName == null) { return; } if (jobException == null) { System.Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:{jobName.ToString()} 结束调度!"); } else { System.Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}:{jobName.ToString()} 调度任务异常!异常信息:{jobException}"); } var loggerId = context.Get("loggerId"); if (loggerId == null) { return; } var entityLogger = _LoggerManager.GetLoggerByIdAsync(Convert.ToInt32(loggerId)).Result; if (entityLogger == null) { return; } entityLogger.ExecEndTime = DateTime.Now; if (jobException == null) { entityLogger.IsException = false; entityLogger.Note = "调度成功"; } else { entityLogger.IsException = true; entityLogger.Note = $"调度异常:{jobException.InnerException.InnerException.Message}"; } _LoggerManager.UpdateLoggerAsync(entityLogger); }
public void Execute(IJobExecutionContext context) { object param = context.Get(callParam);// 参数列表 1-> 执行事件 2->执行事件的参数 JobKey jobkey = context.JobDetail.Key; JobDataMap dm = context.JobDetail.JobDataMap; object[] dmp = dm.Get(callParam) as object[]; if (dmp == null || dmp.Length < 2) { return; } QuartzJobCallBack call = dmp[0] as QuartzJobCallBack; call(dmp[1]); // throw new NotImplementedException(); }
public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException) { JobExecutionData data = context.Get("JobExecutionData") as JobExecutionData; if (data != null) { data.JobEndTime = DateTime.Now; lock (_Data) { if (_Data.Count > _Capacity) { _Data.RemoveAt(0); } _Data.Add(data); } } }
private void OnExecute(IJobExecutionContext context) { Log4NetLogger.Instance.Info(string.Format("FileMonitoringJob with ID {0} Invoked.", jobSetting.Id)); try { jobSetting = (FileJobSetting)context.Get("JobSetting"); //TODO: Processing based on FileJobSetting and notification (DB and Live) HubProxy.Invoke(AppSettingsValues.EventToAdmin, true, "FileMonitoringJob Executed on " + DateTime.Now); } catch (Exception ex) { Log4NetLogger.Instance.Error(ex); } Log4NetLogger.Instance.Info(string.Format("FileMonitoringJob with ID {0} Completed.", jobSetting.Id)); }
public Task Execute(IJobExecutionContext context) { Thread.Sleep(TimeSpan.FromMinutes(1)); // get job data var contextMergedJobData = context.MergedJobDataMap["Name"]?.ToString(); var jobDataName = context.Get("Name"); // do some work, call a service var response = Services.Any(new Hello { Name = contextMergedJobData ?? "there!" }); context.Result = response.Result; return(context.AsTaskResult()); }
public void Execute(IJobExecutionContext context) { try { var urls = context.Get("urls").ToString().Split(','); urls.ToList().ForEach(url => { var request = (HttpWebRequest)WebRequest.Create(url); var s = new Stopwatch(); s.Start(); using (var response = (HttpWebResponse)request.GetResponse()) using (var stream = response.GetResponseStream()) { string ret = string.Empty; if (stream != null) { string readToEnd = new StreamReader(stream).ReadToEnd(); ret = string.Format("{0}...", readToEnd.Substring(0, 500)); } s.Stop(); Publish(new PingerModel() { Time = DateTime.Now, Url = url, response = ret, Status = response.StatusCode.ToString(), StatusDescription = response.StatusDescription, Duration = s.Elapsed, ContentLength = response.ContentLength, ContentType = response.ContentType }); } }); } catch (Exception ex) { throw new JobExecutionException(ex); } }
/// <summary> /// This method used by Quartz, not intendent to use manually. Calling this method directly would cause infinite loop /// </summary> /// <param name="context"></param> public virtual void Execute(IJobExecutionContext context) { Test = (context.Get("Test") as bool?).GetValueOrDefault(); ExecuteInternal(context); }
public void Execute(IJobExecutionContext context) { Automation.Modules.GroupMeModule.NagChoreGroup((string)context.Get("ChoreGroup")); }
public static void KillJob(this IScheduler scheduler, IJobExecutionContext job, IProcessManager processManager) { int processId = (int)job.Get(Constants.FieldNames.ProcessId); processManager.KillProcess(processId); }
public static string ReadOutputBufferContents(this IJobExecutionContext context) { return(context.Get(Constants.FieldNames.StandardOutput).ToString()); }
public void Execute(IJobExecutionContext context) { JobConductorService.Default.EnqueueJob((string)context.Get("JobName")); }
public void Execute(IJobExecutionContext context) { var csvProcessor = context.Get("processor") as CsvProcessor; RunJob(csvProcessor); }