Beispiel #1
0
        public override Process StartProcess()
        {
            ProcessStartupParam param = StartupParam;

            return(new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = param.FileName,//fileinstallmainclassdllpath,
                    Arguments = param.Config,
                    WorkingDirectory = param.WorkDir,
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow = true
                }
            });
        }
Beispiel #2
0
        public IProcessBuilder GetBuilder(ProcessStartupParam parm)

        {
            IProcessBuilder result = null;

            if (!_builders.ContainsKey(parm.Flag))
            {
                //throw new Exception($"{parm.Flag}不支持");
                result = _standardProcess;
            }
            else
            {
                result = _builders[parm.Flag];
            }

            result.StartupParam = parm;
            return(result);
        }
        public override Process StartProcess()
        {
            ProcessStartupParam parm = StartupParam;
            //
            //  string args= $" -jar {parm.FileName} --config {parm.Config} " ;

            string url = parm.AppConfig["service_url"];
            Uri    uri = null;

            try
            {
                uri = new Uri(url);
            }
            catch
            {
                string err = $"{url}不是正确的格式";
                LogHelper.AddTaskLog(err, parm.TaskModel.id);
                throw new Exception(err);
            }


            string args     = $" -jar {parm.FileName} --server.port={uri.Port} ";
            string fileName = GlobalConfig.JavaPath + @"\java ";

            LogHelper.AddTaskLog($"start:{fileName} {args}", parm.TaskModel.id);

            var result = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = fileName, //fileinstallmainclassdllpath,

                    Arguments              = args,
                    UseShellExecute        = false,
                    WorkingDirectory       = parm.WorkDir,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true,
                }
            };

            return(result);
        }
Beispiel #4
0
        public override Process StartProcess()
        {
            ProcessStartupParam param = StartupParam;
            string shell  = param.WorkDir + @"\" + "FastFish.Service.Shell.exe";
            var    result = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = shell, //fileinstallmainclassdllpath,

                    Arguments              = $"--run {param.FileName} --args {param.Config}",
                    UseShellExecute        = false,
                    WorkingDirectory       = param.WorkDir,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true
                }
            };

            return(result);
        }
Beispiel #5
0
 public Process Load(ProcessStartupParam parm)
 {
     /* const uint NORMAL_PRIORITY_CLASS = 0x0020;
      * string args=$" -jar {fileName}";
      * string app = fileName;
      * WinApi.PROCESS_INFORMATION pInfo = new WinApi.PROCESS_INFORMATION();
      * WinApi.STARTUPINFO sInfo = new WinApi.STARTUPINFO();
      * WinApi.SECURITY_ATTRIBUTES pSec = new WinApi.SECURITY_ATTRIBUTES();
      * WinApi.SECURITY_ATTRIBUTES tSec = new WinApi.SECURITY_ATTRIBUTES();
      * pSec.nLength = Marshal.SizeOf(pSec);
      * tSec.nLength = Marshal.SizeOf(tSec);
      * bool retValue;
      * retValue =  WinApi.CreateProcess(app, args,ref pSec,ref tSec,false,NORMAL_PRIORITY_CLASS,
      *   IntPtr.Zero,null,ref sInfo,out pInfo);*/
     /*  switch (parm.Flag)
      * {
      *
      *
      *
      *    case "jar":
      *
      *        return StarJarProcess(parm.FileName,parm.Config, parm.WorkDir);
      *
      *    //return pInfo.dwProcessId;
      *    case "cron":
      *        return StartCronProcess(parm.FileName,parm.WorkDir);
      *
      * }*/
     /*   if (!_builders.ContainsKey(parm.Flag))
      * {
      *     //throw new Exception($"{parm.Flag}不支持");
      *   return   _standardProcess.StartProcess(parm);
      * }
      *
      * return _builders[parm.Flag].StartProcess(parm);*/
     return(null);
 }
        public override Process StartProcess()
        {
            ProcessStartupParam param = StartupParam;

            XXF.Common.IOHelper.CopyDirectory(GlobalConfig.CronShell, param.WorkDir);
            TaskSystemRuntimeInfo info = new TaskSystemRuntimeInfo()
            {
                TaskModel         = new tb_task_model(),
                TaskConnectString = param.TaskDbConnection
            };

            PropertyHelper.Copy(param.TaskModel, info.TaskModel);
            byte[] bytes   = Encoding.Default.GetBytes(info.ToJson());
            string jobData = Convert.ToBase64String(bytes);
            string args    = $" --cron \"{param.Cron}\" " +
                             $" --dll {param.FileName}" +
                             $" --name_space {param.NameSpace} " +
                             $" --config {param.Config} " +
                             $" --job_data {jobData}";

            LogHelper.AddTaskLog($"args:{args}", param.TaskModel.id);
            var result = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = param.WorkDir + @"\" + "FastFish.Cron.exe ", //fileinstallmainclassdllpath,

                    Arguments              = args,
                    UseShellExecute        = false,
                    WorkingDirectory       = param.WorkDir,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true,
                }
            };

            return(result);
        }
        /// <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);
                //taskruntimeinfo.ProcessId=taskdal.GetProcess(c, taskid);
            });
            //如果异常退出,进程后没有更新

            /*if (taskruntimeinfo.TaskModel.task_type == TaskType.Service.Code)
             * {
             *
             * }*/
            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;
            string shelldlldir = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\" + GlobalConfig.TaskShellDir;

            XXF.Common.IOHelper.CreateDirectory(filelocalcachepath);
            XXF.Common.IOHelper.CreateDirectory(fileinstallpath);
            // File.WriteAllBytes(filelocalcachepath, taskruntimeinfo.TaskVersionModel.zipfile);
            FileStream fs = new FileStream(filelocalcachepath, FileMode.Create, FileAccess.ReadWrite);

            SqlHelper.ExcuteSql(GlobalConfig.TaskDataBaseConnectString, (c) =>
            {
                tb_version_dal versiondal = new tb_version_dal();
                versiondal.FillByteToFile(c, taskid, taskruntimeinfo.TaskModel.taskversion, fs);
            });
            fs.Close();
            if (Directory.Exists(fileinstallpath))
            {
                File.SetAttributes(fileinstallpath, FileAttributes.Normal);
                Directory.Delete(fileinstallpath, true);
            }
            CompressHelper.UnCompress(filelocalcachepath, fileinstallpath);
            //拷贝共享程序集

            XXF.Common.IOHelper.CopyDirectory(taskshareddlldir, fileinstallpath);
            //如果是module



            if (taskruntimeinfo.TaskModel.IsModule)
            {
                XXF.Common.IOHelper.CopyDirectory(shelldlldir, fileinstallpath);
            }
            LogHelper.AddTaskLog($"原程序集版本:{taskruntimeinfo.TaskVersionModel.assemblyversion}", taskid);
            //LogHelper.AddTaskLog($"程序集文件:{fileinstallmainclassdllpath}",taskid);
            string assemblyVersion = null;

            byte[] bytes = Encoding.Default.GetBytes(taskruntimeinfo.TaskModel
                                                     .taskappconfigjson);
            string jsonConfig = Convert.ToBase64String(bytes);
            bool   r          = false;

            if (taskruntimeinfo.TaskModel.task_type == TaskType.Service.Code)
            {
                bool            is_module = taskruntimeinfo.TaskModel.IsModule;
                IProcessBuilder builder;
                //当
                //
                try
                {
                    // string assemblyVersion = GetAssemblyVersion(fileinstallmainclassdllpath);
                    Process result;

                    string flag = taskruntimeinfo.TaskModel.ServiceFlag;



                    var startupParam = new ProcessStartupParam()
                    {
                        Flag             = flag, FileName = fileinstallmainclassdllpath,
                        FilePatten       = taskruntimeinfo.TaskModel.taskmainclassdllfilename,
                        Config           = jsonConfig, WorkDir = fileinstallpath,
                        Cron             = taskruntimeinfo.TaskModel.taskcron,
                        NameSpace        = taskruntimeinfo.TaskModel.taskmainclassnamespace,
                        TaskDbConnection = GlobalConfig.TaskDataBaseConnectString,
                        TaskModel        = taskruntimeinfo.TaskModel,
                        AppConfig        = new XXF.Serialization.JsonHelper().Deserialize <TaskAppConfigInfo>(taskruntimeinfo
                                                                                                              .TaskModel
                                                                                                              .taskappconfigjson)
                    };

                    builder = ProcessStart.GetInstance().GetBuilder(startupParam);
                    builder.GetMainFileName();
                    assemblyVersion = builder.GetAssemblyVersion();
                    //     taskruntimeinfo.TaskModel.taskmainclassdllfilename = builder.StartupParam.FileName;
                    result = builder.StartProcess();



                    r = StartProcess(taskid, taskruntimeinfo, result);
                }
                catch (Exception ex)
                {
                    LogHelper.AddTaskLog($"节点开启任务失败{ex.Message}", taskid);
                    throw;
                }
                // bool r = TaskPoolManager.CreateInstance().Add(taskid.ToString(), taskruntimeinfo);
                SqlHelper.ExcuteSql(GlobalConfig.TaskDataBaseConnectString, (c) =>
                {
                    tb_task_dal taskdal = new tb_task_dal();
                    //更新类型
                    taskdal.Edit(c, taskruntimeinfo.TaskModel);
                    taskdal.UpdateTaskState(c, taskid, (int)EnumTaskState.Running);
                    taskdal.UpdateProcess(c, taskid, taskruntimeinfo.Process.Id);
                    //程序集版本更新
                    if (!string.IsNullOrEmpty(assemblyVersion))
                    {
                        if (taskruntimeinfo.TaskVersionModel.assemblyversion != assemblyVersion)
                        {
                            taskruntimeinfo.TaskVersionModel.assemblyversion = assemblyVersion;
                            tb_version_dal versiondal = new tb_version_dal();
                            versiondal.UpdateAssemblyVersion(c, taskruntimeinfo.TaskVersionModel.id, assemblyVersion);
                        }
                    }
                });
                //
                if (taskruntimeinfo.TaskModel.IsRegister == 1)
                {
                    ConsulRegisteration item = _consulRegisterMgr.Parse(taskruntimeinfo.TaskModel);
                    item.Service = builder.GetService();
                    taskruntimeinfo.RegistService = item;
                    _consulRegisterMgr.Register(item);
                }

                LogHelper.AddTaskLog("节点开启任务成功", taskid);
                return(r);
            }
            else
            {
                //以dll加载的方式处理,基本已废弃
                assemblyVersion = GetAssemblyVersion(fileinstallmainclassdllpath);

                if (!string.IsNullOrEmpty(taskruntimeinfo.TaskModel.ServiceFlag))
                {
                    return(StartTaskProcess(taskid, taskruntimeinfo, fileinstallmainclassdllpath,
                                            fileinstallpath, jsonConfig, assemblyVersion));
                }
                else
                {
                    try
                    {
                        var dlltask = new AppDomainLoader <BaseDllTask>().Load(fileinstallmainclassdllpath,
                                                                               taskruntimeinfo.TaskModel.taskmainclassnamespace, out taskruntimeinfo.Domain);
                        //  dlltask.Domain = taskruntimeinfo.Domain;
                        var sdktaskmodel = new XXF.BaseService.TaskManager.model.tb_task_model();
                        PropertyHelper.Copy(taskruntimeinfo.TaskModel, sdktaskmodel);
                        dlltask.SystemRuntimeInfo = new TaskSystemRuntimeInfo()
                        {
                            TaskConnectString = GlobalConfig.TaskDataBaseConnectString,
                            TaskModel         = sdktaskmodel
                        };

                        dlltask.AppConfig = new TaskAppConfigInfo();
                        if (!string.IsNullOrEmpty(taskruntimeinfo.TaskModel.taskappconfigjson))
                        {
                            dlltask.AppConfig =
                                new XXF.Serialization.JsonHelper().Deserialize <TaskAppConfigInfo>(taskruntimeinfo
                                                                                                   .TaskModel
                                                                                                   .taskappconfigjson);
                        }

                        taskruntimeinfo.DllTask = dlltask;

                        /*   if (dlltask is IMicroService)
                         * {
                         *     taskruntimeinfo.TaskModel.task_type = TaskType.Service.Code;
                         * }
                         * else
                         * {
                         *     taskruntimeinfo.TaskModel.task_type = TaskType.Task.Code;
                         *
                         * }*/

                        r = TaskPoolManager.CreateInstance().Add(taskid.ToString(), taskruntimeinfo);
                        SqlHelper.ExcuteSql(GlobalConfig.TaskDataBaseConnectString, (c) =>
                        {
                            tb_task_dal taskdal = new tb_task_dal();
                            //更新类型
                            taskdal.Edit(c, taskruntimeinfo.TaskModel);
                            taskdal.UpdateTaskState(c, taskid, (int)EnumTaskState.Running);
                            //程序集版本更新
                            if (!string.IsNullOrEmpty(assemblyVersion))
                            {
                                if (taskruntimeinfo.TaskVersionModel.assemblyversion != assemblyVersion)
                                {
                                    taskruntimeinfo.TaskVersionModel.assemblyversion = assemblyVersion;
                                    tb_version_dal versiondal = new tb_version_dal();
                                    versiondal.UpdateAssemblyVersion(c, taskruntimeinfo.TaskVersionModel.id,
                                                                     assemblyVersion);
                                }
                            }
                        });

                        LogHelper.AddTaskLog("节点开启任务成功", taskid);
                        return(r);
                    }
                    catch (Exception exp)
                    {
                        DisposeTask(taskid, taskruntimeinfo, true);
                        throw exp;
                    }
                }
            }
        }
        private bool StartTaskProcess(int taskid, NodeTaskRuntimeInfo taskruntimeinfo, string
                                      fileinstallmainclassdllpath, string fileinstallpath, string jsonConfig,
                                      string assemblyVersion)
        {
            bool is_module = taskruntimeinfo.TaskModel.IsModule;

            //当
            //
            try
            {
                Process result;

                string flag = taskruntimeinfo.TaskModel.ServiceFlag;



                var startupParam = new ProcessStartupParam()
                {
                    Flag             = flag,
                    FileName         = fileinstallmainclassdllpath,
                    Config           = jsonConfig,
                    WorkDir          = fileinstallpath,
                    Cron             = taskruntimeinfo.TaskModel.taskcron,
                    NameSpace        = taskruntimeinfo.TaskModel.taskmainclassnamespace,
                    TaskDbConnection = GlobalConfig.TaskDataBaseConnectString,
                    TaskModel        = taskruntimeinfo.TaskModel
                };

                result = ProcessStart.GetInstance().Load(startupParam);



                StartProcess(taskid, taskruntimeinfo, result);
            }
            catch (Exception ex)
            {
                LogHelper.AddTaskLog($"节点开启任务失败{ex.Message}", taskid);
                throw;
            }
            bool r = TaskPoolManager.CreateInstance().Add(taskid.ToString(), taskruntimeinfo);

            SqlHelper.ExcuteSql(GlobalConfig.TaskDataBaseConnectString, (c) =>
            {
                tb_task_dal taskdal = new tb_task_dal();
                //更新类型
                taskdal.Edit(c, taskruntimeinfo.TaskModel);
                taskdal.UpdateTaskState(c, taskid, (int)EnumTaskState.Running);
                taskdal.UpdateProcess(c, taskid, taskruntimeinfo.Process.Id);
                //程序集版本更新
                if (!string.IsNullOrEmpty(assemblyVersion))
                {
                    if (taskruntimeinfo.TaskVersionModel.assemblyversion != assemblyVersion)
                    {
                        taskruntimeinfo.TaskVersionModel.assemblyversion = assemblyVersion;
                        tb_version_dal versiondal = new tb_version_dal();
                        versiondal.UpdateAssemblyVersion(c, taskruntimeinfo.TaskVersionModel.id, assemblyVersion);
                    }
                }
            });
            //

            LogHelper.AddTaskLog("节点开启任务成功", taskid);
            return(r);
        }