Пример #1
0
        private void DoJob()
        {
            var st = new Stopwatch();

            st.Start();

            #region [备份并删除会员任务数据]

            const int step      = 1000;
            var       startGuid = Guid.Empty;
            var       index     = 0;
            var       sw        = new Stopwatch();
            sw.Start();
            if (!CheckSwitch())
            {
                Logger.Warn($"数据备份开关关闭-->step4-->备份并删除会员任务数据-->startGuid:{startGuid};step:{step}");
                return;
            }

            var userList = DalTaskBackup.GetUserList(step, startGuid);
            //var userList = new List<Guid> { new Guid("{51cf3203-d28a-4226-b771-6734d8144980}"),new Guid("{0165d634-bd37-47bd-9cc3-3bae23db3823}"),
            //new Guid("{ceee291d-7acb-410a-b4aa-5cfa634bd749}"),new Guid("{430cd5a7-4336-460d-8037-95e2ff3af178}"),new Guid("{1c188e5b-5c9d-42ab-8f2a-4cae8bfb86e6}"),new Guid("{452f1ca9-6f83-4ed1-9b9b-18251310a409}"),new Guid("{97cd1f54-12e6-8f43-2bd1-97d80c1f14fb}") };

            //var userList = new List<Guid> { new Guid("93F1B820-9F61-4C1E-B1A9-550349FB8A23") };
            while (userList.Any())
            {
                var backupCount  = DalTaskBackup.BackupUserTaskInfo(userList);
                var deletedCount = DalTaskBackup.DeleteData(userList);
                sw.Stop();
                Logger.Info(
                    $"带备份数据第{index}批,用时{sw.ElapsedMilliseconds}毫秒,备份{backupCount}条数据,删除{deletedCount}条数据,最小用户ID是{startGuid},分批步长为{step}条");
                startGuid = userList.Last();
                index++;
                sw.Reset();
                sw.Start();
                if (!CheckSwitch())
                {
                    Logger.Warn($"数据备份开关关闭-->step2-->备份并删除会员任务数据-->startGuid:{startGuid};step:{step}");
                    return;
                }

                userList = DalTaskBackup.GetUserList(step, startGuid);
                //userList = new List<Guid>();
            }

            st.Stop();
            Logger.Info($"TaskDataBackupStep2Job-->Step2完成-->用时{st.ElapsedMilliseconds}毫秒");

            #endregion
        }
        private void DoJob()
        {
            #region [备份已删除任务数据]

            if (!CheckSwitch())
            {
                Logger.Warn("数据备份开关关闭-->step1->备份已删除任务数据");
                return;
            }

            var st = new Stopwatch();
            st.Start();
            var backupCount = DalTaskBackup.BackupDeletedTask();
            Logger.Info($"备份已删除任务数据{backupCount}条!");


            if (!CheckSwitch())
            {
                Logger.Warn("数据备份开关关闭-->清理已删除任务数据");
                return;
            }

            var deletedCount = DalTaskBackup.DeleteData();
            Logger.Warn($"删除已备份数据{deletedCount}条!");

            if (!CheckSwitch())
            {
                Logger.Warn("数据备份开关关闭-->清理已删除任务详情数据");
                return;
            }
            var deleteCount2 = DalTaskBackup.DeleteDetailDate();
            Logger.Warn($"删除已删除任务详情记录{deleteCount2}条");

            st.Stop();
            Logger.Info($"TaskDataBackupStep1Job-->Step1完成-->用时{st.ElapsedMilliseconds}毫秒");
            #endregion
        }