Exemple #1
0
        public ActionResult RecoverAccount(long accountId)
        {
            var backgroundJobService = new BackgroundJobService();

            _homeService.RecoverAccount(accountId, backgroundJobService);
            return(RedirectToAction("Index", "DeletedUsers"));
        }
Exemple #2
0
        /// <summary>
        ///  默认调度器服务,需要长期一直运行,对于后台只进行,返回状态值更新
        /// </summary>
        /// <param name="Scheduler"></param>
        public void JobSchedulerMain(IScheduler Scheduler)
        {
            BackgroundJob jobInfo = new BackgroundJobService().GetBackgroundJobManage();

            if (jobInfo == null)//默认job
            {
                //throw new Exception("查找不到默认JobManager");
                ////禁止使用默认job 保值job调度正确运行
                //return;
                jobInfo = new BackgroundJob()
                {
                    assemblyName = "MZ.Jobs.exe",
                    className    = "MZ.Jobs.JobItems.ManagerJob",
                    cron         = "0/10 * * * * ?",//5秒钟调用
                    jobId        = CustomerConfig.Managerjobkey,
                    name         = "defaultMainJob",
                    jobType      = ((int)BackgroundJobType.Manager).ToString()
                };
            }
            JobKey jobKey = new JobKey(jobInfo.jobId, "Group");

            if (Scheduler.CheckExists(jobKey) == false)
            {
                ScheduleJob(Scheduler, jobInfo);
            }
        }
Exemple #3
0
        public ActionResult UpdatePost(BackgroundJobInfo Info)
        {
            var result = new ResponseResult();
            BackgroundJobService _BackgroundJobService = new BackgroundJobService();

            result.success = _BackgroundJobService.UpdateBackgroundJob(Info);
            return(Json(result));
        }
Exemple #4
0
 internal ActorRuntime(IActorSystem system, ActorGrain grain)
 {
     System     = system;
     Timers     = new TimerService(grain);
     Jobs       = new BackgroundJobService(grain);
     Reminders  = new ReminderService(grain);
     Activation = new ActivationService(grain);
 }
Exemple #5
0
        public ActionResult Delete(string idList)
        {
            var result = new ResponseResult();
            BackgroundJobService _BackgroundJobService = new BackgroundJobService();

            result.success = _BackgroundJobService.DeleteBackgroundJobLog(Utils.StringToGuidList(idList));
            result.message = result.success == true ? "操作成功" : "操作失败";
            return(Json(result));
        }
Exemple #6
0
        public ActionResult InfoData(System.Guid BackgroundJobLogId)
        {
            var result = new ResponseResult();
            BackgroundJobService _BackgroundJobService = new BackgroundJobService();

            result.data    = _BackgroundJobService.GetBackgroundJobLogInfo(BackgroundJobLogId);
            result.success = true;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemple #7
0
        public ActionResult AddPost(BackgroundJobInfo Info)
        {
            var result = new ResponseResult();
            BackgroundJobService _BackgroundJobService = new BackgroundJobService();

            Info.BackgroundJobId = System.Guid.NewGuid();
            result.success       = _BackgroundJobService.InsertBackgroundJob(Info);
            return(Json(result));
        }
        public ActionResult UpdateState(System.Guid BackgroundJobId, int State)
        {
            var result = new ResponseResult();
            BackgroundJobService _BackgroundJobService = new BackgroundJobService();

            result.success = _BackgroundJobService.UpdateBackgroundJobState(BackgroundJobId, State);
            result.message = result.success == true ? "操作成功" : "操作失败";
            return(Json(result));
        }
Exemple #9
0
        public ActionResult Delete(string idList)
        {
            var result = new ResponseResult();
            BackgroundJobService _BackgroundJobService = new BackgroundJobService();
            string rtMsg = string.Empty;

            result.success = _BackgroundJobService.DeleteBackgroundJob(Utils.StringToGuidList(idList), out rtMsg);
            result.message = rtMsg;
            return(Json(result));
        }
Exemple #10
0
        public ActionResult List()
        {
            BackgroundJobService _BackgroundJobService = new BackgroundJobService();
            var data   = _BackgroundJobService.GetBackgroundJobLogInfoPagerList(this.GetPageParameter());
            var result = new ResponseResult()
            {
                success = true, message = "数据获取成功", data = data
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemple #11
0
        public ActionResult UpdateState(System.Guid backgroundJobId, int state)
        {
            var success = new BackgroundJobService().UpdateBackgroundJobState(backgroundJobId, state);
            var message = success == true ? "操作成功" : "操作失败";

            return(Json(new ResponseResult()
            {
                success = success,
                message = message
            }));
        }
Exemple #12
0
        /// <summary>
        ///1.请求客户配置是否发生了改变,没改变保持当前运行,通知服务进行更新\
        ///2.判断配置是否超过指定时间,后需要刷新下最新的Configuration
        ///3.当获取的List为0的时候如何判断是否因为网络原因而不是因为服务端无配置
        /// </summary>
        /// <returns></returns>
        public bool CanContinueJobScheduler()
        {
            var dateExipre = false;

            if ((DateTime.Now - lastExecDate).TotalSeconds >= CustomerConfig.JobListCacheTime / 1000)    //1小时执行一次最新情况
            {
                dateExipre = true;
                return(true);
            }
            var hasChange = new BackgroundJobService().ConfigurationHasChange();

            return(hasChange || dateExipre);
        }
        public void Run(IRunJobModel runModel)
        {
            var account = runModel.Account;
            var forSpy  = runModel.ForSpy;
            var friend  = runModel.Friend;

            if (account.GroupSettingsId == null)
            {
                return;
            }

            if (!new FunctionPermissionManager().HasPermissions(FunctionName.InviteToGroups, (long)account.GroupSettingsId))
            {
                return;
            }

            var settings = new GroupService(new NoticeService()).GetSettings((long)account.GroupSettingsId);
            var inviteTheNewGroupLaunchTime = new TimeSpan(settings.RetryTimeInviteTheGroupsHour, settings.RetryTimeInviteTheGroupsMin, settings.RetryTimeInviteTheGroupsSec);

            var model = new CreateBackgroundJobModel
            {
                Account          = account,
                FunctionName     = FunctionName.InviteToGroups,
                LaunchTime       = inviteTheNewGroupLaunchTime,
                CheckPermissions = true,
                IsForSpy         = forSpy
            };

            new JobStateService().DeleteJobState(new JobStateViewModel
            {
                AccountId    = account.Id,
                FunctionName = FunctionName.InviteToGroups,
                FriendId     = friend.Id,
                IsForSpy     = forSpy
            });

            var jobIsSuccessfullyCreated = new BackgroundJobService().CreateBackgroundJob(model);

            if (!jobIsSuccessfullyCreated)
            {
                return;
            }

            new JobQueueService().AddToQueue(new JobQueueViewModel
            {
                AccountId    = account.Id,
                FunctionName = FunctionName.InviteToGroups,
                FriendId     = friend.Id,
                IsForSpy     = forSpy
            });
        }
Exemple #14
0
        public void Run(IRunJobModel runModel)
        {
            var account = runModel.Account;
            var friend  = runModel.Friend;
            var forSpy  = runModel.ForSpy;

            if (account.GroupSettingsId == null)
            {
                return;
            }

            var settings = new GroupService(new NoticeService()).GetSettings((long)account.GroupSettingsId);
            var winkFriendsLaunchTime = new TimeSpan(settings.RetryTimeForWinkFriendsHour, settings.RetryTimeForWinkFriendsMin, settings.RetryTimeForWinkFriendsSec);

            var model = new CreateBackgroundJobModel
            {
                Account          = account,
                FunctionName     = FunctionName.Wink,
                LaunchTime       = winkFriendsLaunchTime,
                CheckPermissions = true,
                IsForSpy         = forSpy
            };

            new JobStateService().DeleteJobState(new JobStateViewModel
            {
                AccountId    = account.Id,
                FunctionName = FunctionName.Wink,
                IsForSpy     = forSpy
            });

            var jobIsSuccessfullyCreated = new BackgroundJobService().CreateBackgroundJob(model);

            if (!jobIsSuccessfullyCreated)
            {
                return;
            }

            new JobQueueService().AddToQueue(new JobQueueViewModel
            {
                AccountId    = account.Id,
                FunctionName = FunctionName.Wink,
                IsForSpy     = forSpy
            });
        }
Exemple #15
0
        /// <summary>
        /// Job状态管控
        /// </summary>
        /// <param name="Scheduler"></param>
        public void JobScheduler(IScheduler Scheduler)
        {
            List <BackgroundJobInfo> list = new BackgroundJobService().GeAllowScheduleJobInfoList();

            if (list != null && list.Count > 0)
            {
                foreach (BackgroundJobInfo jobInfo in list)
                {
                    JobKey jobKey = new JobKey(jobInfo.BackgroundJobId.ToString(), jobInfo.BackgroundJobId.ToString() + "Group");
                    if (Scheduler.CheckExists(jobKey) == false)
                    {
                        if (jobInfo.State == 1 || jobInfo.State == 3)
                        {
                            ScheduleJob(Scheduler, jobInfo);
                            if (Scheduler.CheckExists(jobKey) == false)
                            {
                                new BackgroundJobService().UpdateBackgroundJobState(jobInfo.BackgroundJobId, 0);
                            }
                            else
                            {
                                new BackgroundJobService().UpdateBackgroundJobState(jobInfo.BackgroundJobId, 1);
                            }
                        }
                        else if (jobInfo.State == 5)
                        {
                            new BackgroundJobService().UpdateBackgroundJobState(jobInfo.BackgroundJobId, 0);
                        }
                    }
                    else
                    {
                        if (jobInfo.State == 5)
                        {
                            Scheduler.DeleteJob(jobKey);
                            new BackgroundJobService().UpdateBackgroundJobState(jobInfo.BackgroundJobId, 0);
                        }
                        else if (jobInfo.State == 3)
                        {
                            new BackgroundJobService().UpdateBackgroundJobState(jobInfo.BackgroundJobId, 1);
                        }
                    }
                }
            }
        }
Exemple #16
0
        /// <summary>
        /// Job状态管控
        /// </summary>
        /// <param name="Scheduler"></param>
        public void JobScheduler(IScheduler Scheduler)
        {
            //请求客户配置是否发生了改变,没改变保持当前运行,通知服务进行更新
            var canContinue = CanContinueJobScheduler();

            if (canContinue == false)
            {
                return;
            }


            List <BackgroundJob> list = new BackgroundJobService().GeAllowScheduleJobInfoList();

            JobLogger.Info($"获得Job个数:{list.Count}");
            //定时获取job数据,此处需要判断数据为0的情况是因为网络情况导致的异常
            if (list != null && list.Count > 0)
            {
                var allRunningJobKeys = new List <JobKey>();
                lastExecDate = DateTime.Now;
                foreach (BackgroundJob jobInfo in list)
                {
                    ///保证只有一个managerjob运行,且管理job不能停止;默认运行器的ID将联系对应管理JOB删除默认job
                    if (jobInfo.jobType == ((int)BackgroundJobType.Manager).ToString() && jobInfo.jobId != CustomerConfig.Managerjobkey)//有当前的默认job
                    {
                        JobKey managerJobKey = new JobKey(CustomerConfig.Managerjobkey, "Group");
                        if (Scheduler.CheckExists(managerJobKey))
                        {
                            Scheduler.DeleteJob(managerJobKey);//删除默认job
                        }
                    }
                    JobKey jobKey = new JobKey(jobInfo.jobId.ToString(), "Group");

                    ///job不存在
                    if (Scheduler.CheckExists(jobKey) == false)
                    {
                        if (jobInfo.state == (int)BackgroundJobStateType.Running || jobInfo.state == (int)BackgroundJobStateType.Luanch)
                        {
                            ScheduleJob(Scheduler, jobInfo);
                            if (Scheduler.CheckExists(jobKey) == false)
                            {
                                //设置为停止
                                new BackgroundJobService().UpdateBackgroundJobState(jobInfo.jobId, (int)BackgroundJobStateType.Stop);
                            }
                            else
                            {
                                if (!allRunningJobKeys.Contains(jobKey))
                                {
                                    allRunningJobKeys.Add(jobKey);
                                }
                                ////设置为运行中
                                new BackgroundJobService().UpdateBackgroundJobState(jobInfo.jobId, (int)BackgroundJobStateType.Running);
                            }
                        }
                        else if (jobInfo.state == (int)BackgroundJobStateType.Stopping)
                        {
                            ////设置为停止
                            new BackgroundJobService().UpdateBackgroundJobState(jobInfo.jobId, (int)BackgroundJobStateType.Stop);
                        }
                    }
                    else//已经在运行
                    {
                        if (jobInfo.state == (int)BackgroundJobStateType.Stopping)
                        {
                            Scheduler.DeleteJob(jobKey);
                            ////设置为停止
                            new BackgroundJobService().UpdateBackgroundJobState(jobInfo.jobId, (int)BackgroundJobStateType.Stop);
                        }
                        else if (jobInfo.state == (int)BackgroundJobStateType.Luanch)
                        {
                            if (!allRunningJobKeys.Contains(jobKey))
                            {
                                allRunningJobKeys.Add(jobKey);
                            }
                            ////设置为运行
                            new BackgroundJobService().UpdateBackgroundJobState(jobInfo.jobId, (int)BackgroundJobStateType.Running);
                        }
                        else if (jobInfo.state == (int)BackgroundJobStateType.Running)
                        {
                            if (!allRunningJobKeys.Contains(jobKey))
                            {
                                allRunningJobKeys.Add(jobKey);
                            }
                        }
                    }
                }
                //检查无效状态的任务
                InvalidJobCheck(Scheduler, allRunningJobKeys);
            }
        }