/// <summary> /// 通过任务编码获得任务信息 /// </summary> /// <param name="missionCode"></param> /// <returns></returns> public static ZD_SyncTaskConfig GetTaskInfoByCode(string missionCode) { string sql = @"SELECT [MissionCode] ,[MissionName] ,[SyncTime] ,[SyncSuccessTime] ,[IsAyncSuccess] ,[JobClassName] ,[State] ,[CronExplain],[SyncSuccessBeginTime],[HostName] FROM [H3Cloud].[dbo].[ZD_SyncTaskConfig] where MissionCode='" + missionCode + "'"; OThinker.Data.Database.CommandFactory factory = OThinker.H3.WorkSheet.AppUtility.Engine.EngineConfig.CommandFactory; OThinker.Data.Database.ICommand command = factory.CreateCommand(); var dataTable = command.ExecuteDataTable(sql); ZD_SyncTaskConfig result = new ZD_SyncTaskConfig(); if (dataTable.Rows.Count > 0) { result.MissionCode = missionCode; result.MissionName = dataTable.Rows[0]["MissionName"] + string.Empty; result.SyncSuccessTime = Convert.ToDateTime(dataTable.Rows[0]["SyncSuccessTime"]); result.SyncTime = Convert.ToDateTime(dataTable.Rows[0]["SyncTime"]); result.SyncSuccessBeginTime = Convert.ToDateTime(dataTable.Rows[0]["SyncSuccessBeginTime"]); result.IsAyncSuccess = Convert.ToInt32(dataTable.Rows[0]["IsAyncSuccess"]); result.State = Convert.ToInt32(dataTable.Rows[0]["State"]); result.JobClassName = dataTable.Rows[0]["JobClassName"] + string.Empty; result.CronExplain = dataTable.Rows[0]["CronExplain"] + string.Empty; result.HostName = dataTable.Rows[0]["HostName"] + string.Empty; } else { result = null; } return(result); }
public static bool UpdateMissionPlan(ZD_SyncTaskConfig model) { Dictionary <string, object> param = new Dictionary <string, object>(); param.Add("MissionCode", "'" + model.MissionCode + "'"); Dictionary <string, object> data = new Dictionary <string, object>(); data.Add("MissionName", "'" + model.MissionName + "'"); data.Add("SyncSuccessTime", "'" + model.SyncSuccessTime + "'"); data.Add("SyncTime", "'" + model.SyncTime + "'"); data.Add("JobClassName", "'" + model.JobClassName + "'"); data.Add("State", model.State); data.Add("IsAyncSuccess", model.IsAyncSuccess); data.Add("CronExplain", "'" + model.CronExplain + "'"); data.Add("HostName", "'" + model.HostName + "'"); data.Add("SyncSuccessBeginTime", "'" + model.SyncSuccessBeginTime + "'"); string result = InvestHelper.UpdateTable(data, param, "ZD_SyncTaskConfig"); if (result.IndexOf("true") > 0) { return(true); } else { return(false); } }
public static void Stop(ZD_SyncTaskConfig plan) { IScheduler scheduler = _scheduler; TriggerKey triggerKey = new TriggerKey(plan.JobClassName.Trim() + "TriggerName"); scheduler.DeleteJob(new JobKey(plan.JobClassName.Trim(), plan.JobClassName.Trim() + "GroupName")); }
public void Execute(IJobExecutionContext context) { jobKey = context.JobDetail.Key; ZD_SyncTaskConfig plan = MissionSyncHelper.GetTaskInfoByCode(jobKey.Name); _logger.InfoFormat("Execute---- {0} 执行中断时间 {1}", jobKey, DateTime.Now.ToString()); }
public void Execute(IJobExecutionContext context) { IJobDetail jobDetail = context.JobDetail; ZD_SyncTaskConfig plan = (ZD_SyncTaskConfig)jobDetail.JobDataMap.Get("Plan"); try { DateTime SyncSuccessBeginTime = DateTime.Now; //开辟新线程处理 Thread thread = new Thread(ThreadMethod); thread.Start(plan); //TimeToGo planJob = new TimeToGo(JobMethod); //planJob(plan); //JobMethod(plan); plan.SyncSuccessBeginTime = SyncSuccessBeginTime; MissionSyncHelper.PlanSuccessUpdate(plan); } catch (Exception e) { MissionSyncHelper.PlanFailUpdate(plan); _logger.InfoFormat(e.Message.ToString()); throw; } }
private void ThreadMethod(Object obj) { ZD_SyncTaskConfig plan = (ZD_SyncTaskConfig)obj; TimeToGo planJob = new TimeToGo(JobMethod); planJob(plan); }
/// <summary> /// 通过任务编码获得任务信息 /// </summary> /// <param name="missionCode"></param> /// <returns></returns> public static ZD_SyncTaskConfig GetTaskInfoByCode(string missionCode) { string sql = @"SELECT [ObjectId], [MissionCode] ,[MissionName] ,[SyncTime] ,[SyncSuccessTime] ,[IsAyncSuccess] ,[JobClassName] ,[State] ,[CronExplain],[SyncSuccessBeginTime],[HostName] FROM [ZD_SyncTaskConfig] where MissionCode='" + missionCode + "'"; var dataTable = DapperHelper.CreateInstance().SimpleQuery <ZD_SyncTaskConfig>(sql); ZD_SyncTaskConfig result = new ZD_SyncTaskConfig(); if (dataTable.Count > 0) { result.ObjectId = dataTable[0].ObjectId; result.MissionCode = missionCode; result.MissionName = dataTable[0].MissionName + string.Empty; result.SyncSuccessTime = dataTable[0].SyncSuccessTime; result.SyncTime = dataTable[0].SyncTime; result.SyncSuccessBeginTime = dataTable[0].SyncSuccessBeginTime; result.IsAyncSuccess = dataTable[0].IsAyncSuccess; result.State = dataTable[0].State; result.JobClassName = dataTable[0].JobClassName + string.Empty; result.CronExplain = dataTable[0].CronExplain + string.Empty; result.HostName = dataTable[0].HostName + string.Empty; } else { result = null; } return(result); }
public ActionResult StopPlan(string MissionCodes) { ZD_SyncTaskConfig plan = new ZD_SyncTaskConfig(); plan = MissionSyncHelper.GetTaskInfoByCode(MissionCodes); plan.State = 0; MissionSyncHelper.UpdateMissionPlan(plan); //启动定时任务 JobScheduler.Stop(plan); _logger.InfoFormat(plan.MissionName + "=============禁止时间时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); return(AjaxJson(true, "", "", "")); }
public static bool UpdateMissionPlan(ZD_SyncTaskConfig model) { int result = DapperHelper.CreateInstance().UpdateTable <ZD_SyncTaskConfig>("ZD_SyncTaskConfig", model); if (result > 0) { return(true); } else { return(false); } }
public static bool AddMissionPlan(ZD_SyncTaskConfig data) { List <ZD_SyncTaskConfig> list = new List <ZD_SyncTaskConfig>(); list.Add(data); string result = InvestHelper.InsertTableBatch <ZD_SyncTaskConfig>(new JavaScriptSerializer().Serialize(list), "ZD_SyncTaskConfig"); if (result.IndexOf("true") > 0) { return(true); } else { return(false); } }
public void Execute(IJobExecutionContext context) { IJobDetail jobDetail = context.JobDetail; ZD_SyncTaskConfig plan = (ZD_SyncTaskConfig)jobDetail.JobDataMap.Get("Plan"); try { _logger.InfoFormat(plan.MissionName + "=============开始执行时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "============="); MissionSyncHelper.PlanSuccessUpdate(plan); } catch (Exception e) { MissionSyncHelper.PlanFailUpdate(plan); _logger.InfoFormat(e.Message.ToString()); throw; } }
public static bool PlanFailUpdate(ZD_SyncTaskConfig model) { model.IsAyncSuccess = 0;//失败 model.SyncTime = DateTime.Now; bool flag = UpdateMissionPlan(model); if (flag) { _logger.InfoFormat(model.MissionName + "=============执行失败============="); return(true); } else { _logger.InfoFormat(model.MissionName + "=============更新状态失败============="); return(false); } }
public static bool PlanSuccessUpdate(ZD_SyncTaskConfig model) { model.IsAyncSuccess = 1;//成功 model.SyncTime = DateTime.Now; model.SyncSuccessTime = DateTime.Now; bool flag = UpdateMissionPlan(model); if (flag) { _logger.InfoFormat(model.MissionName + "=============成功执行时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "============="); return(true); } else { _logger.InfoFormat(model.MissionName + "=============更新状态失败============="); return(false); } }
public void Execute(IJobExecutionContext context) { IJobDetail jobDetail = context.JobDetail; ZD_SyncTaskConfig plan = (ZD_SyncTaskConfig)jobDetail.JobDataMap.Get("Plan"); try { DateTime SyncSuccessBeginTime = DateTime.Now; JobMethod(plan); plan.SyncSuccessBeginTime = SyncSuccessBeginTime; MissionSyncHelper.PlanSuccessUpdate(plan); } catch (Exception e) { MissionSyncHelper.PlanFailUpdate(plan); _logger.InfoFormat(e.Message.ToString()); throw; } }
/// <summary> /// 应用程序启动时从新启动已开启的任务 /// </summary> public static void StartPlan() { try { string sql = @"SELECT [MissionCode] ,[MissionName] ,[SyncTime] ,[SyncSuccessTime] ,[IsAyncSuccess] ,[JobClassName] ,[State] ,[CronExplain],[SyncSuccessBeginTime],[HostName] FROM [H3Cloud].[dbo].[ZD_SyncTaskConfig] where State=1 and HostName='" + Dns.GetHostName() + "'"; OThinker.Data.Database.CommandFactory factory = OThinker.H3.WorkSheet.AppUtility.Engine.EngineConfig.CommandFactory; OThinker.Data.Database.ICommand command = factory.CreateCommand(); var dataTable = command.ExecuteDataTable(sql); if (dataTable.Rows.Count > 0) { for (int i = 0; i < dataTable.Rows.Count; i++) { ZD_SyncTaskConfig result = new ZD_SyncTaskConfig(); result.MissionCode = dataTable.Rows[i]["MissionCode"] + string.Empty; result.MissionName = dataTable.Rows[i]["MissionName"] + string.Empty; result.SyncSuccessTime = Convert.ToDateTime(dataTable.Rows[i]["SyncSuccessTime"]); result.SyncTime = Convert.ToDateTime(dataTable.Rows[i]["SyncTime"]); result.SyncSuccessBeginTime = Convert.ToDateTime(dataTable.Rows[i]["SyncSuccessBeginTime"]); result.IsAyncSuccess = Convert.ToInt32(dataTable.Rows[i]["IsAyncSuccess"]); result.State = 1; result.JobClassName = dataTable.Rows[i]["JobClassName"] + string.Empty; result.CronExplain = dataTable.Rows[i]["CronExplain"] + string.Empty; result.HostName = dataTable.Rows[i]["HostName"] + string.Empty; OThinker.H3.Portal.JobScheduler.Start(result); } } } catch (Exception e) { _logger.InfoFormat(e.Message.ToString()); throw; } }
/// <summary> /// 应用程序启动时从新启动已开启的任务 /// </summary> public static void StartPlan() { try { string sql = @"SELECT [ObjectId], [MissionCode] ,[MissionName] ,[SyncTime] ,[SyncSuccessTime] ,[IsAyncSuccess] ,[JobClassName] ,[State] ,[CronExplain],[SyncSuccessBeginTime],[HostName] FROM [ZD_SyncTaskConfig] where State=1 and HostName='" + Dns.GetHostName() + "'"; var dataList = DapperHelper.CreateInstance().SimpleQuery <ZD_SyncTaskConfig>(sql); if (dataList.Count > 0) { foreach (var item in dataList) { ZD_SyncTaskConfig result = new ZD_SyncTaskConfig(); result.ObjectId = item.ObjectId + string.Empty; result.MissionCode = item.MissionCode + string.Empty; result.MissionName = item.MissionName + string.Empty; result.SyncSuccessTime = item.SyncSuccessTime; result.SyncTime = item.SyncTime; result.SyncSuccessBeginTime = item.SyncSuccessBeginTime; result.IsAyncSuccess = item.IsAyncSuccess; result.State = 1; result.JobClassName = item.JobClassName + string.Empty; result.CronExplain = item.CronExplain + string.Empty; result.HostName = item.HostName + string.Empty; JobScheduler.JobScheduler.Start(result); } } } catch (Exception e) { _logger.InfoFormat(e.Message.ToString()); throw; } }
/// <summary> /// 定时任务数据变更 /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult EditTaskPlan(ZD_SyncTaskConfig model, string type) { int scalCount = 0; switch (type) { case "change": List <ZD_SyncTaskConfig> planList = _zD_SyncTaskConfigService.SelectData <ZD_SyncTaskConfig>("select * from ZD_SyncTaskConfig where ObjectId='" + model.ObjectId + "'"); planList[0].MissionName = model.MissionName; planList[0].MissionCode = model.MissionCode; planList[0].JobClassName = model.JobClassName; planList[0].State = model.State; planList[0].CronExplain = model.CronExplain; scalCount = _zD_SyncTaskConfigService.UpdateTable <ZD_SyncTaskConfig>(planList[0]); break; case "add": model.ObjectId = Guid.NewGuid().ToString(); model.SyncTime = DateTime.Now; model.SyncSuccessTime = DateTime.Now; model.SyncSuccessBeginTime = DateTime.Now; scalCount = _zD_SyncTaskConfigService.Insert <ZD_SyncTaskConfig>(model); break; default: break; } if (scalCount > 0) { return(AjaxJson(true, 1, "成功.", "")); } else { return(AjaxJson(false, 0, "", "失败.")); } }
public static void Start(ZD_SyncTaskConfig plan) { try { IScheduler scheduler = _scheduler; if (scheduler.IsStarted) { } else { } scheduler.Start(); IDictionary <string, Object> jobData = new Dictionary <string, Object>(); jobData.Add("Plan", plan); //Type objType = typeof(T); Type objType = Type.GetType("OThinker.H3.Portal." + plan.JobClassName.Trim()); IJobDetail job = JobBuilder.Create(objType) .WithIdentity(plan.JobClassName.Trim(), plan.JobClassName.Trim() + "GroupName") .SetJobData(new JobDataMap(jobData)) .Build(); ITrigger trigger; trigger = TriggerBuilder.Create() .WithIdentity(plan.JobClassName.Trim() + "TriggerName", plan.JobClassName.Trim() + "GroupName") .WithCronSchedule(plan.CronExplain.Trim()) .ForJob(job) .Build(); scheduler.ScheduleJob(job, trigger); _logger.InfoFormat(plan.MissionName + "=============启动时间时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } catch (Exception e) { _logger.InfoFormat("============="); _logger.InfoFormat(e.Message.ToString()); throw; } }
public override void JobMethod(ZD_SyncTaskConfig plan) { _logger.InfoFormat(plan.MissionName + "=============开始执行时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "============="); }
/// <summary> /// 只需重写该虚拟方法便可 /// </summary> /// <param name="plan"></param> public virtual void JobMethod(ZD_SyncTaskConfig plan) { }