예제 #1
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);
                }
                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);
        }
예제 #2
0
파일: AppBatchTask.cs 프로젝트: zgren/dp2
        // 按照命令启动一个批处理任务(不是自动启动)
        // 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
        }