Exemplo n.º 1
0
        private string CloseTaskJob(JobModel model)
        {
            try
            {
                //执行作业前任务
                Log.Write(model.taskName, "[关闭任务]开始>>>>>>" + model.taskName + "_" + model.id, "成功");
                //生成作业名称,作业名称=任务名称 +任务ID+序号
                string jobName = model.taskName + "_" + model.id;
                //更新任务状态
                string sno = JOB_PRIFEX + jobName;

                ValidationErrors errors = new ValidationErrors();
                TaskJob.UpdateState(ref errors, sno, 2, "关闭任务");
                /////////////////////////////////////////////////
                //取当前程序集
                Assembly assem = Assembly.GetExecutingAssembly();

                //创建任务对象并执行
                Object o = assem.CreateInstance(model.taskName, false,
                                                BindingFlags.ExactBinding,
                                                null, new Object[] { }, null, null);

                MethodInfo m   = assem.GetType(model.taskName).GetMethod("CloseJob"); //默认调用方法
                Object     ret = m.Invoke(o, new Object[] { model });                 //参数

                Log.Write(model.taskName, "<<<<<<<[关闭任务]结束" + model.taskName + "_" + model.id, "成功");

                return(ret.ToString());
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemplo n.º 2
0
        //执行作业前任务
        private string RunBefore(JobModel model)
        {
            try
            {
                //执行作业前任务
                Log.Write(model.taskName, "[前置任务]开始>>>>>>" + model.taskName + "_" + model.id, "成功");

                //取当前程序集
                Assembly assem = Assembly.GetExecutingAssembly();

                //创建任务对象并执行
                Object o = assem.CreateInstance(model.taskName, false,
                                                BindingFlags.ExactBinding,
                                                null, new Object[] { }, null, null);

                MethodInfo m   = assem.GetType(model.taskName).GetMethod("RunJobBefore"); //默认调用方法
                Object     ret = m.Invoke(o, new Object[] { model });                     //参数


                //更新任务状态
                string sno = JOB_PRIFEX + model.taskName + "_" + model.id;

                ValidationErrors errors = new ValidationErrors();
                TaskJob.UpdateState(ref errors, sno, 0, "初始化数据");

                Log.Write(model.taskName, "<<<<<<<[前置任务]结束" + model.taskName + "_" + model.id, "成功");

                return(ret.GetString());
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemplo n.º 3
0
        public bool ResumeTaskJob(string sno, ref ValidationErrors errors)
        {
            try
            {
                if (string.IsNullOrEmpty(sno))
                {
                    errors.Add("任务序号不能为空");
                    return(false);
                }
                /////////////////////////////////////////////////////////////
                // construct a scheduler factory
                ISchedulerFactory schedFact = new StdSchedulerFactory();

                // get a scheduler
                IScheduler sched = schedFact.GetScheduler();
                /////////////////////////////////////////////////////////////////////////

                //重启任务
                int count = 0;
                foreach (var group in sched.GetJobGroupNames())
                {
                    var jobKeys = sched.GetJobKeys(GroupMatcher <JobKey> .GroupEquals(group));
                    foreach (var jobkey in jobKeys)
                    {
                        if (jobkey.Name.Contains(sno))
                        {
                            sched.ResumeJob(jobkey);
                            TaskJob.UpdateState(ref errors, sno, 4, "重启");
                            count++;
                        }
                    }
                }
                if (count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                return(false);
            }
        }
Exemplo n.º 4
0
        public virtual void Execute(IJobExecutionContext context)
        {
            ValidationErrors validationErrors = new ValidationErrors();
            //取状态值
            JobDataMap dataMap    = context.JobDetail.JobDataMap;
            string     id         = dataMap.GetString(ID);          //任务ID
            string     taskName   = dataMap.GetString(TASKNAME);    //任务名称
            string     procName   = dataMap.GetString(PROCNAME);    //过程名称
            string     procParams = dataMap.GetString(PROCPARARMS); //过程参数
            //
            JobKey jobKey  = context.JobDetail.Key;
            string jobName = jobKey.Name;//任务名称=任务名称+任务ID

            try
            {
                //开始执行业务逻辑
                Log.Write(jobName, "开始任务[过程]>>>>>>" + jobName, "成功");

                ////过程入口
                using (DBContainer db = new DBContainer())
                {
                    db.P_JOB_ENTERY(jobName);
                }



                //////////////////////////////////////////////////////////////////
                if (validationErrors.Count > 0)
                {
                    Log.Write(jobName, "Error", validationErrors.Error);
                    //更新任务状态
                    TaskJob.UpdateState(ref validationErrors, jobName, 1, "失败");
                }
                Log.Write(jobName, "<<<<<<<结束任务[过程]" + jobName, "成功");
                //更新任务状态
                TaskJob.UpdateState(ref validationErrors, jobName, 1, "成功");
            }
            catch (System.Exception e)
            {
                Log.Write(jobName, "Exception", e.Message);
                JobExecutionException e2 = new JobExecutionException(e);
                e2.UnscheduleAllTriggers = true;
                throw e2;
            }
        }
Exemplo n.º 5
0
        public virtual void Execute(IJobExecutionContext context)
        {
            ValidationErrors validationErrors = new ValidationErrors();
            //取状态值
            JobDataMap dataMap  = context.JobDetail.JobDataMap;
            string     id       = dataMap.GetString(ID);       //任务ID
            string     taskName = dataMap.GetString(TASKNAME); //任务名称
            //
            JobKey jobKey  = context.JobDetail.Key;
            string jobName = jobKey.Name;//任务名称=任务名称+任务ID

            try
            {
                //开始执行业务逻辑
                Log.Write(jobName, "开始任务>>>>>>" + jobName, "成功");


                //取当前程序集
                Assembly assem = Assembly.GetExecutingAssembly();

                //创建任务对象并执行
                Object o = assem.CreateInstance(taskName, false,
                                                BindingFlags.ExactBinding,
                                                null, new Object[] { }, null, null);

                MethodInfo m   = assem.GetType(taskName).GetMethod("RunJob");//默认调用方法
                Object     ret = m.Invoke(o, new Object[] { dataMap, jobName, id, taskName });
                //更新任务状态
                TaskJob.UpdateState(ref validationErrors, jobName, 1, ret.ToString());

                //////////////////////////////////////////////////////////////////
                if (validationErrors.Count > 0)
                {
                    Log.Write(jobName, "Error", validationErrors.Error);
                }
                Log.Write(jobName, "<<<<<<<结束任务" + jobName, "成功");
            }
            catch (System.Exception e)
            {
                Log.Write(jobName, "Exception", e.Message);
                JobExecutionException e2 = new JobExecutionException(e);
                e2.UnscheduleAllTriggers = true;
                throw e2;
            }
        }