Exemplo n.º 1
0
        private static void Test()
        {
            var nodes = ConfigurationManager.GetMySqlClusterSettings();

            for (int i = 0; i < nodes.Nodes.Count; i++)
            {
                string configs = nodes.Nodes[i].AutoMoveDataSet;
                List <AutoMoveDataConfig> ls = AutoMoveDataConfig.Parse(configs);
                Console.WriteLine(String.Format("节点:{1},ID:{2},共{0}个配置表", ls.Count, nodes.Nodes[i].DataBasesName, nodes.Nodes[i].ID));
                for (int r = 0; r < ls.Count; r++)
                {
                    Console.WriteLine(String.Format("表{0}:{1},数据保鲜期:{2}天,时间标识列:{3},任务计划时间:{4},归档节点ID:{5}", r + 1, ls[r].TableName, ls[r].DataHoldDays, ls[r].DateField, ls[r].ScheduleTime, ls[r].ArchiveNodeID));
                }
            }
        }
Exemplo n.º 2
0
        private static void Status()
        {
            Console.WriteLine("work path:");
            Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
            Console.WriteLine(AppDomain.CurrentDomain.DynamicDirectory);
            Console.WriteLine("log path:");
            string logpath = ConfigurationManager.GetAppConfig("LogManPath");

            Console.WriteLine(String.Format("{0},existed? {1}", logpath, Directory.Exists(logpath)));
            Console.WriteLine("");
            var nodes = ConfigurationManager.GetMySqlClusterSettings();

            for (int i = 0; i < nodes.Nodes.Count; i++)
            {
                string configs = nodes.Nodes[i].AutoMoveDataSet;
                List <AutoMoveDataConfig> ls = AutoMoveDataConfig.Parse(configs);
                Console.WriteLine(String.Format("节点:{1},ID:{2},共{0}个配置表", ls.Count, nodes.Nodes[i].DataBasesName, nodes.Nodes[i].ID));
                for (int r = 0; r < ls.Count; r++)
                {
                    Console.WriteLine(String.Format("表{0}:{1},数据保鲜期:{2}天,时间标识列:{3},任务计划时间:{4},归档节点ID:{5}", r + 1, ls[r].TableName, ls[r].DataHoldDays, ls[r].DateField, ls[r].ScheduleTime, ls[r].ArchiveNodeID));
                }
            }

            Console.WriteLine("");
            Console.WriteLine("任务计划如下:");
            if (service == null)
            {
                var s = AppDomain.CurrentDomain.GetData("service");
                if (s != null)
                {
                    service = (IDataNiuKnifeService <AppSettings>)s;
                }
            }

            if (service != null)
            {
                for (int i = 0; i < service.JobList.Count; i++)
                {
                    Console.WriteLine(service.JobList[i].Description);
                }
            }
            else
            {
                Console.WriteLine("there is no job service instances.");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 启动服务
        /// </summary>
        private async void StartServices(CancellationToken stoppingToken = default(CancellationToken))
        {
            //初始化过程……
            //按每个节点配置Job
            //1.创建Schedule
            m_Scheduler = await StdSchedulerFactory.GetDefaultScheduler();

            Loger.Info(this.GetType(), "开始初始化服务……");

            try
            {
                //遍历所有节点,解析带有数据分割配置的节点创建job队列
                if (m_MySqlClusterSettings != null && m_MySqlClusterSettings.Nodes.Count > 0)
                {
                    foreach (var node in m_MySqlClusterSettings.Nodes)
                    {
                        if (!String.IsNullOrEmpty(node.AutoMoveDataSet))
                        {
                            List <AutoMoveDataConfig> ls = AutoMoveDataConfig.Parse(node.AutoMoveDataSet);
                            if (ls != null && ls.Count > 0)
                            {
                                //m_ConfiguredDataNode.Add(node, ls);
                                for (int k = 0; k < ls.Count; k++)
                                {
                                    //2.创建job (具体的job需要单独在一个文件中执行)
                                    var job = JobBuilder.Create <MysqlDataWorker>()
                                              .UsingJobData("conn_source_str", node.ConnStr)
                                              .UsingJobData("conn_dest_str", m_MySqlClusterSettings.Nodes.FindLast(o => o.ID.Equals(ls[k].ArchiveNodeID)).ConnStr)
                                              .UsingJobData("table_name", ls[k].TableName)
                                              .UsingJobData("key_name", ls[k].KeyName)
                                              .UsingJobData("data_hold_days", ls[k].DataHoldDays)
                                              .UsingJobData("date_field", ls[k].DateField)
                                              .WithIdentity("job_" + k, "g_" + node.DataBasesName)
                                              .WithDescription(String.Format("自动分割数据表:{0},每天在{1}执行一次", ls[0].TableName, ls[k].ScheduleTime))
                                              .StoreDurably(true)
                                              .Build();

                                    m_JobList.Add(job);

                                    //3.创建触发器
                                    TimeOfDay timeOfDay = new TimeOfDay(ls[k].ScheduleTime.Hours, ls[k].ScheduleTime.Minutes, ls[k].ScheduleTime.Seconds);
                                    ITrigger  trigger   = TriggerBuilder.Create().WithDailyTimeIntervalSchedule(x => x.OnEveryDay().StartingDailyAt(timeOfDay).EndingDailyAfterCount(1)).Build();
                                    //ITrigger trigger_test = TriggerBuilder.Create().WithDailyTimeIntervalSchedule(x => x.OnEveryDay().WithInterval(1, IntervalUnit.Minute)).Build();
                                    await m_Scheduler.ScheduleJob(job, trigger);

                                    //await m_Scheduler.ScheduleJob(job, trigger_test);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Loger.Error(this.GetType(), "初始化服务失败," + ex.Message, ex);
            }

            StringBuilder sb = new StringBuilder();

            if (m_JobList.Count > 0)
            {
                sb.AppendLine("开始初始化服务结束");
                for (int i = 0; i < m_JobList.Count; i++)
                {
                    sb.AppendLine(m_JobList[i].Description);
                }

                Loger.Info(this.GetType(), sb.ToString());
                await m_Scheduler.Start(stoppingToken);
            }

            AppDomain.CurrentDomain.SetData("service", this);
        }