Example #1
0
        public void Start()
        {
            Log.Info("任务计划已启动......");

            //服务列队
            int serviceQueue = ConfigProvider.GetAppSetting <int>("Winner.Job.Master.Queue", 0);

            //初始化,获取列队服务
            Log.Info("初始化任务计划列队中......");
            try
            {
                JobQueue.Instance.Init(serviceQueue);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                //throw ex;
            }
            Log.Info(string.Format("已加载{0}列队共有{1}个服务", serviceQueue, JobQueue.Instance.Jobs.Count));
            while (true)
            {
                var services = JobQueue.Instance.Jobs;
                //线程集合
                List <Task> tasks = new List <Task>();
                foreach (var job in services)
                {
                    if (job.Status == (int)JobStatus.暂停 ||
                        (job.NextRunTime.HasValue && job.NextRunTime.Value > DateTime.Now))
                    {
                        continue;
                    }

                    tasks.Add(Task.Factory.StartNew(() =>
                    {
                        //执行服务
                        Log.Info("开始执行:Service = " + job.ServiceName);
                        JobService jobServcie = new JobService();
                        jobServcie.Execute(job);
                        Log.Info("执行完毕:Service = " + job.ServiceName);
                    }));
                }
                //线程同步
                Log.Info("同步任务计划线程中......");
                Task.WaitAll(tasks.ToArray());
                //TODO:根据最近需要执行的任务计算出时间,然后进行定时处理
                var lateTime = services.Min(s => s.NextRunTime.Value - DateTime.Now);
                if (lateTime.TotalMilliseconds < 0)
                {
                    continue;
                }
                //间隔30秒
                Log.Info("任务计划休眠" + lateTime.TotalMinutes + "分钟......");
                System.Threading.Thread.Sleep(lateTime);
            }
        }
Example #2
0
 public void InitSiteConfig()
 {
     if (Site == null)
     {
         Site = new SiteConfig()
         {
             SiteName         = "会员中心",
             UserSystemDomain = ConfigProvider.GetAppSetting("User.Domain"),
             SSODomain        = ConfigProvider.GetAppSetting("SSO.Domain"),
             ShopDemain       = ConfigProvider.GetAppSetting("Shop.Domain"),
         };
         Site.SSOLogin    = Site.SSOUrl("account/login?service=" + HttpUtility.UrlEncode(this.Request.Url.AbsoluteUri));
         Site.SSOlogout   = Site.SSOUrl("account/logout");
         Site.SSORegister = Site.SSOUrl("account/register?service=" + HttpUtility.UrlEncode(this.Request.Url.AbsoluteUri));
     }
 }