Beispiel #1
0
 public void Execute(JobExecutionContext context)
 {
     try
     {
         int taskid          = Convert.ToInt32(context.JobDetail.Name);
         var taskruntimeinfo = TaskPoolManager.CreateInstance().Get(taskid.ToString());
         if (taskruntimeinfo == null || taskruntimeinfo.DllTask == null)
         {
             LogHelper.AddTaskError("当前任务信息为空引用", taskid, new Exception());
             return;
         }
         taskruntimeinfo.TaskLock.Invoke(() => {
             try
             {
                 taskruntimeinfo.DllTask.TryRun();
             }
             catch (Exception exp)
             {
                 LogHelper.AddTaskError("任务" + taskid + "TaskJob回调时执行失败", taskid, exp);
             }
         });
     }
     catch (Exception exp)
     {
         LogHelper.AddNodeError("任务回调时严重系统级错误", exp);
     }
 }
Beispiel #2
0
        /// <summary>
        /// 静态初始化
        /// </summary>
        static TaskPoolManager()
        {
            _taskpoolmanager = new TaskPoolManager();
            ISchedulerFactory sf = new StdSchedulerFactory();

            _sched = sf.GetScheduler();
            _sched.Start();
        }
Beispiel #3
0
        /// <summary>
        /// 任务的卸载
        /// </summary>
        /// <param name="taskid"></param>
        /// <returns></returns>
        public bool Uninstall(int taskid)
        {
            var taskruntimeinfo = TaskPoolManager.CreateInstance().Get(taskid.ToString());

            if (taskruntimeinfo == null)
            {
                throw new Exception("任务不在运行中");
            }
            var r = DisposeTask(taskid, taskruntimeinfo, true);

            SqlHelper.ExcuteSql(GlobalConfig.TaskDataBaseConnectString, (c) =>
            {
                tb_task_dal taskdal = new tb_task_dal();
                taskdal.UpdateTaskState(c, taskid, (int)EnumTaskState.Stop);
            });
            LogHelper.AddTaskLog("节点卸载任务成功", taskid);
            return(r);
        }
Beispiel #4
0
        /// <summary>
        /// 任务的开启
        /// </summary>
        /// <param name="taskid"></param>
        /// <returns></returns>
        public bool Start(int taskid)
        {
            var taskruntimeinfo = TaskPoolManager.CreateInstance().Get(taskid.ToString());

            if (taskruntimeinfo != null)
            {
                throw new Exception("任务已在运行中");
            }

            taskruntimeinfo          = new NodeTaskRuntimeInfo();
            taskruntimeinfo.TaskLock = new TaskLock();
            SqlHelper.ExcuteSql(GlobalConfig.TaskDataBaseConnectString, (c) =>
            {
                tb_task_dal taskdal              = new tb_task_dal();
                taskruntimeinfo.TaskModel        = taskdal.Get(c, taskid);
                tb_version_dal versiondal        = new tb_version_dal();
                taskruntimeinfo.TaskVersionModel = versiondal.GetCurrentVersion(c, taskid, taskruntimeinfo.TaskModel.taskversion);
            });
            string filelocalcachepath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\" + GlobalConfig.TaskDllCompressFileCacheDir + @"\" + taskruntimeinfo.TaskModel.id + @"\" + taskruntimeinfo.TaskModel.taskversion + @"\" +
                                        taskruntimeinfo.TaskVersionModel.zipfilename;
            string fileinstallpath             = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\" + GlobalConfig.TaskDllDir + @"\" + taskruntimeinfo.TaskModel.id;
            string fileinstallmainclassdllpath = fileinstallpath + @"\" + taskruntimeinfo.TaskModel.taskmainclassdllfilename;
            string taskshareddlldir            = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\" + GlobalConfig.TaskSharedDllsDir;

            BSF.Tool.IOHelper.CreateDirectory(filelocalcachepath);
            BSF.Tool.IOHelper.CreateDirectory(fileinstallpath);
            System.IO.File.WriteAllBytes(filelocalcachepath, taskruntimeinfo.TaskVersionModel.zipfile);

            CompressHelper.UnCompress(filelocalcachepath, fileinstallpath);
            //拷贝共享程序集
            BSF.Tool.IOHelper.CopyDirectory(taskshareddlldir, fileinstallpath);
            try
            {
                new TaskAssemblyRedirect().TryRebulidDll(fileinstallmainclassdllpath, taskruntimeinfo.TaskModel.taskmainclassnamespace);
                var dlltask      = new AppDomainLoader <BaseDllTask>().Load(fileinstallmainclassdllpath, taskruntimeinfo.TaskModel.taskmainclassnamespace, out taskruntimeinfo.Domain);
                var sdktaskmodel = new BSF.BaseService.TaskManager.Model.tb_task_model();
                PropertyHelper.Copy(taskruntimeinfo.TaskModel, sdktaskmodel);
                dlltask.SystemRuntimeInfo = new TaskSystemRuntimeInfo()
                {
                    TaskConnectString = GlobalConfig.TaskDataBaseConnectString,
                    TaskModel         = sdktaskmodel
                };
                //加载AppConfig配置
                var appconfig = new TaskAppConfigInfo();
                if (!string.IsNullOrEmpty(taskruntimeinfo.TaskModel.taskappconfigjson))
                {
                    appconfig = new BSF.Serialization.JsonProvider().Deserialize <TaskAppConfigInfo>(taskruntimeinfo.TaskModel.taskappconfigjson);
                }
                SqlHelper.ExcuteSql(GlobalConfig.TaskDataBaseConnectString, (c) =>
                {
                    tb_config_dal configdal = new tb_config_dal();
                    var cs = configdal.GetList(c);
                    foreach (var o in cs)
                    {
                        if (!appconfig.ContainsKey(o.configkey))
                        {
                            appconfig.Add(o.configkey, o.configvalue);
                        }
                    }
                });

                dlltask.AppConfig       = appconfig;
                taskruntimeinfo.DllTask = dlltask;
                bool r = TaskPoolManager.CreateInstance().Add(taskid.ToString(), taskruntimeinfo);
                SqlHelper.ExcuteSql(GlobalConfig.TaskDataBaseConnectString, (c) =>
                {
                    tb_task_dal taskdal = new tb_task_dal();
                    taskdal.UpdateTaskState(c, taskid, (int)EnumTaskState.Running);
                });
                LogHelper.AddTaskLog("节点开启任务成功", taskid);
                return(r);
            }
            catch (Exception exp)
            {
                DisposeTask(taskid, taskruntimeinfo, true);
                throw exp;
            }
        }