// 获得任务当前信息 // 多线程:安全 public BatchTaskInfo GetCurrentInfo(long lResultStart, int nMaxResultBytes) { this.m_lock.AcquireReaderLock(m_nLockTimeout); try { BatchTaskInfo info = new BatchTaskInfo(); info.Name = this.Name; if (this.m_bClosed == false) info.State = "运行中"; else info.State = "停止"; if (this.App.PauseBatchTask == true) info.ProgressText = "[注意:全部批处理任务已经被暂停] " + this.ProgressText; else info.ProgressText = this.ProgressText; byte[] baResultText = null; long lOffset = 0; long lTotalLength = 0; this.GetResultText(lResultStart, nMaxResultBytes, out baResultText, out lOffset, out lTotalLength); info.ResultText = baResultText; info.ResultOffset = lOffset; info.ResultTotalLength = lTotalLength; info.ResultVersion = this.ProgressFileVersion; return info; } finally { this.m_lock.ReleaseReaderLock(); } }
// 按照命令启动一个批处理任务(不是自动启动) // return: // -1 出错 // 0 启动成功 // 1 调用前任务已经处于执行状态,本次调用激活了这个任务 public int StartBatchTask(string strName, BatchTaskInfo param, out BatchTaskInfo info, out string strError) { strError = ""; info = null; if (strName == "!continue") { this.PauseBatchTask = false; // 2016/11/6 if (this.BatchTasks == null) { strError = "this.BatchTasks == null"; return(-1); } // 2013/11/23 foreach (BatchTask current_task in this.BatchTasks) { current_task.Activate(); } info = GetTaskInfo("全部批处理任务已经解除暂停"); return(1); } // 2007/12/18 if (this.ContainsHangup("LogRecover") == true) { strError = "当前系统正处在LogRecover挂起状态,无法启动新的批处理任务"; return(-1); } // 2012/2/4 if (this.PauseBatchTask == true) { strError = "当前所有批处理任务均处在暂停状态,无法启动新的批处理任务"; return(-1); } if (this.BatchTasks == null) { strError = "this.BatchTasks == null"; return(-1); } BatchTask task = this.BatchTasks.GetBatchTask(strName); // 创建新的任务 if (task == null) { if (strName == "预约到书管理") { task = new ArriveMonitor(this, strName); } else if (strName == "日志恢复") { task = new OperLogRecover(this, strName); } else if (strName == "dp2Library 同步") { task = new LibraryReplication(this, strName); } else if (strName == "重建检索点") { task = new RebuildKeys(this, strName); } /* * else if (strName == "跟踪DTLP数据库") * task = new TraceDTLP(this, strName); * */ else if (strName == "正元一卡通读者信息同步") { task = new ZhengyuanReplication(this, strName); } else if (strName == "迪科远望一卡通读者信息同步") { task = new DkywReplication(this, strName); } else if (strName == "读者信息同步") { task = new PatronReplication(this, strName); } else if (strName == "超期通知") { task = new ReadersMonitor(this, strName); } else if (strName == "消息监控") { task = new MessageMonitor(this, strName); } else if (strName == "创建 MongoDB 日志库") { task = new BuildMongoOperDatabase(this, strName); } else { strError = "系统不能识别任务名 '" + strName + "'"; return(-1); } try { this.BatchTasks.Add(task); } catch (Exception ex) { strError = ExceptionUtil.GetAutoText(ex); return(-1); } } else { bool bOldStoppedValue = task.Stopped; if (bOldStoppedValue == false) { if (strName == "重建检索点") { task.StartInfos.Add(param.StartInfo); task.AppendResultText("新任务已加入等待队列:\r\n---\r\n" + RebuildKeys.GetSummary(param.StartInfo) + "\r\n---\r\n\r\n"); } else { // 尽量采用前端发来的参数进行运行 task.StartInfo = param.StartInfo; } // 激活 2007/10/10 task.eventActive.Set(); task.ManualStart = true; // 表示为命令启动 strError = "任务 " + task.Name + " 已经在运行中,不能重复启动。本次操作激活了这个任务。"; return(1); } } // 执行日志恢复任务前,需要先中断正在执行的其他任何任务 // TODO: 日志恢复 任务结束后,原先中断的那些任务并不会自动去启动。需要系统管理员手动重新启动一次Application if (strName == "日志恢复") { StopAllBatchTasks(); } task.ManualStart = true; // 表示为命令启动 task.StartInfo = param.StartInfo; task.ClearProgressFile(); // 清除进度文件内容 task.StartWorkerThread(); /* * // 激活 2007/10/10 * task.eventActive.Set(); * */ info = task.GetCurrentInfo(param.ResultOffset, param.MaxResultBytes); return(0); }
// TODO: 如果当前任务正在运行, 需要把新的任务追加到末尾继续运行 int StartRebuildKeysTask(string strDbNameList, out string strError) { strError = ""; BatchTaskInfo info = null; // 参数原始存储的时候,为了避免在参数字符串中发生混淆,数据库名之间用 | 间隔 if (string.IsNullOrEmpty(strDbNameList) == false) strDbNameList = strDbNameList.Replace(",", "|"); BatchTaskStartInfo start_info = new BatchTaskStartInfo(); start_info.Start = "dbnamelist=" + strDbNameList; BatchTaskInfo param = new BatchTaskInfo(); param.StartInfo = start_info; int nRet = StartBatchTask("重建检索点", param, out info, out strError); if (nRet == -1) return -1; return 0; }
// 按照命令启动一个批处理任务(不是自动启动) // return: // -1 出错 // 0 启动成功 // 1 调用前任务已经处于执行状态,本次调用激活了这个任务 public int StartBatchTask(string strName, BatchTaskInfo param, out BatchTaskInfo info, out string strError) { strError = ""; info = null; if (strName == "!continue") { this.PauseBatchTask = false; // 2016/11/6 if (this.BatchTasks == null) { strError = "this.BatchTasks == null"; return(-1); } // 2013/11/23 foreach (BatchTask current_task in this.BatchTasks) { current_task.Activate(); } info = GetTaskInfo("全部批处理任务已经解除暂停"); return(1); } // 2007/12/18 if (this.ContainsHangup("LogRecover") == true) { strError = "当前系统正处在LogRecover挂起状态,无法启动新的批处理任务"; return(-1); } // 2012/2/4 if (this.PauseBatchTask == true) { strError = "当前所有批处理任务均处在暂停状态,无法启动新的批处理任务"; return(-1); } if (this.BatchTasks == null) { strError = "this.BatchTasks == null"; return(-1); } BatchTask task = this.BatchTasks.GetBatchTask(strName); // 创建新的任务 if (task == null) { if (strName == "预约到书管理") { task = new ArriveMonitor(this, strName); } else if (strName == "日志恢复") { task = new OperLogRecover(this, strName); } else if (strName == "dp2Library 同步") { // task = new LibraryReplication(this, strName); strError = "尚未正式提供服务"; // 2017/6/8 return(-1); } else if (strName == "重建检索点") { task = new RebuildKeys(this, strName); } /* * else if (strName == "跟踪DTLP数据库") * task = new TraceDTLP(this, strName); * */ else if (strName == "正元一卡通读者信息同步") { task = new ZhengyuanReplication(this, strName); } else if (strName == "迪科远望一卡通读者信息同步") { task = new DkywReplication(this, strName); } else if (strName == "读者信息同步") { task = new PatronReplication(this, strName); } else if (strName == "超期通知") { task = new ReadersMonitor(this, strName); } else if (strName == "消息监控") { task = new MessageMonitor(this, strName); } else if (strName == "创建 MongoDB 日志库") { task = new BuildMongoOperDatabase(this, strName); } else if (strName == "服务器同步") { task = new ServerReplication(this, strName); } else if (strName == "大备份") { task = new BackupTask(this, strName); } else { strError = "系统不能识别任务名 '" + strName + "'"; return(-1); } try { this.BatchTasks.Add(task); } catch (Exception ex) { strError = ExceptionUtil.GetAutoText(ex); return(-1); } } else { bool bOldStoppedValue = task.Stopped; if (bOldStoppedValue == false) { if (strName == "重建检索点") { task.StartInfos.Add(param.StartInfo); task.AppendResultText("新任务已加入等待队列:\r\n---\r\n" + RebuildKeys.GetSummary(param.StartInfo) + "\r\n---\r\n\r\n"); } else { // 尽量采用前端发来的参数进行运行 task.StartInfo = param.StartInfo; } // 激活 2007/10/10 task.eventActive.Set(); task.ManualStart = true; // 表示为命令启动 int nRet = WaitForBegin( task, strName, param, ref info, out string strError1); if (nRet == 0) { strError = "任务 " + task.Name + " 已经在运行中,不能重复启动。本次操作激活了这个任务。"; return(1); } strError += "; " + strError1; return(1); } } // 执行日志恢复任务前,需要先中断正在执行的其他任何任务 // TODO: 日志恢复 任务结束后,原先中断的那些任务并不会自动去启动。需要系统管理员手动重新启动一次Application if (strName == "日志恢复") { StopAllBatchTasks(); } task.SetProgressText(""); task.ManualStart = true; // 表示为命令启动 task.StartInfo = param.StartInfo; task.ClearProgressFile(); // 清除进度文件内容 task.StartWorkerThread(); /* * // 激活 2007/10/10 * task.eventActive.Set(); * */ return(WaitForBegin( task, strName, param, ref info, out strError)); #if NO // 等待工作线程运行到启动点 if (task.StartInfo.WaitForBegin) { if (task.eventStarted.WaitOne(TimeSpan.FromSeconds(10)) == false) { strError = "任务 " + task.Name + " 未能在 10 秒内启动成功"; return(1); } // 2017/8/23 if (string.IsNullOrEmpty(task.ErrorInfo) == false) { strError = "任务 " + task.Name + " 启动阶段出错: " + task.ErrorInfo; return(1); } } info = task.GetCurrentInfo(param.ResultOffset, param.MaxResultBytes); if (task.StartInfo.WaitForBegin) { if (info.StartInfo == null) { info.StartInfo = new BatchTaskStartInfo(); } if (strName == "大备份") { BackupTask temp = task as BackupTask; info.StartInfo.OutputParam = temp.OutputFileNames; } } return(0); #endif }
public int GetBatchTaskInfo(string strName, BatchTaskInfo param, out BatchTaskInfo info, out string strError) { strError = ""; info = null; BatchTask task = this.BatchTasks.GetBatchTask(strName); // 任务本来就不存在 if (task == null) { strError = "任务 '" + strName + "' 不存在"; return -1; } info = task.GetCurrentInfo(param.ResultOffset, param.MaxResultBytes); return 1; }
public int StopBatchTask(string strName, BatchTaskInfo param, out BatchTaskInfo info, out string strError) { strError = ""; info = null; if (strName == "!pause") { this.PauseBatchTask = true; info = GetTaskInfo("全部批处理任务已经被暂停"); return 1; } BatchTask task = this.BatchTasks.GetBatchTask(strName); // 任务本来就不存在 if (task == null) { strError = "任务 '" + strName + "' 不存在"; return -1; } task.Stop(); info = task.GetCurrentInfo(param.ResultOffset, param.MaxResultBytes); return 1; }
// 按照命令启动一个批处理任务(不是自动启动) // return: // -1 出错 // 0 启动成功 // 1 调用前任务已经处于执行状态,本次调用激活了这个任务 public int StartBatchTask(string strName, BatchTaskInfo param, out BatchTaskInfo info, out string strError) { strError = ""; info = null; if (strName == "!continue") { this.PauseBatchTask = false; // 2013/11/23 foreach (BatchTask current_task in this.BatchTasks) { current_task.Activate(); } info = GetTaskInfo("全部批处理任务已经解除暂停"); return 1; } // 2007/12/18 if (this.HangupReason == HangupReason.LogRecover) { strError = "当前系统正处在LogRecover挂起状态,无法启动新的批处理任务"; return -1; } // 2012/2/4 if (this.PauseBatchTask == true) { strError = "当前所有批处理任务均处在暂停状态,无法启动新的批处理任务"; return -1; } BatchTask task = this.BatchTasks.GetBatchTask(strName); // 创建新的任务 if (task == null) { if (strName == "预约到书管理") task = new ArriveMonitor(this, strName); else if (strName == "日志恢复") task = new OperLogRecover(this, strName); else if (strName == "dp2Library 同步") task = new LibraryReplication(this, strName); else if (strName == "重建检索点") task = new RebuildKeys(this, strName); /* else if (strName == "跟踪DTLP数据库") task = new TraceDTLP(this, strName); * */ else if (strName == "正元一卡通读者信息同步") task = new ZhengyuanReplication(this, strName); else if (strName == "迪科远望一卡通读者信息同步") task = new DkywReplication(this, strName); else if (strName == "读者信息同步") task = new PatronReplication(this, strName); else if (strName == "超期通知") task = new ReadersMonitor(this, strName); else if (strName == "消息监控") task = new MessageMonitor(this, strName); else { strError = "系统不能识别任务名 '" + strName + "'"; return -1; } try { this.BatchTasks.Add(task); } catch (Exception ex) { strError = ex.Message; return -1; } } else { bool bOldStoppedValue = task.Stopped; if (bOldStoppedValue == false) { if (strName == "重建检索点") { task.StartInfos.Add(param.StartInfo); task.AppendResultText("新任务已加入等待队列:\r\n---\r\n" + RebuildKeys.GetSummary(param.StartInfo) + "\r\n---\r\n\r\n"); } else { // 尽量采用前端发来的参数进行运行 task.StartInfo = param.StartInfo; } // 激活 2007/10/10 task.eventActive.Set(); task.ManualStart = true; // 表示为命令启动 strError = "任务 " + task.Name + " 已经在运行中,不能重复启动。本次操作激活了这个任务。"; return 1; } } // 执行日志恢复任务前,需要先中断正在执行的其他任何任务 // TODO: 日志恢复 任务结束后,原先中断的那些任务并不会自动去启动。需要系统管理员手动重新启动一次Application if (strName == "日志恢复") { StopAllBatchTasks(); } task.ManualStart = true; // 表示为命令启动 task.StartInfo = param.StartInfo; task.ClearProgressFile(); // 清除进度文件内容 task.StartWorkerThread(); /* // 激活 2007/10/10 task.eventActive.Set(); * */ info = task.GetCurrentInfo(param.ResultOffset, param.MaxResultBytes); return 0; }
// 获得任务当前信息 // 多线程:安全 public BatchTaskInfo GetTaskInfo(string strText) { BatchTaskInfo info = new BatchTaskInfo(); info.Name = ""; info.State = ""; info.ProgressText = strText; info.ResultText = null; info.ResultOffset = 0; info.ResultTotalLength = 0; info.ResultVersion = 0; return info; }