예제 #1
0
        private void Subscribe()
        {
            cacheNotify.Subscribe <KeyValuePair <string, StartupProgress> >(
                (kv, action) =>
            {
                switch (action)
                {
                case CacheNotifyAction.Remove:
                    tokenSource.Cancel();

                    lock (locker)
                    {
                        progress.Complete();
                        Publish();
                    }
                    break;

                case CacheNotifyAction.InsertOrUpdate:
                    if (!startupProgresses.ContainsKey(kv.Key))
                    {
                        startupProgresses.Add(kv.Key, kv.Value);
                    }
                    else
                    {
                        startupProgresses[kv.Key] = kv.Value;
                    }
                    break;
                }
            });
        }
예제 #2
0
        internal void Start()
        {
            if (!successInitialized ||
                (ConfigurationManagerExtension.AppSettings["web.warmup.enabled"] ?? "false") == "false" ||
                WarmUpSettings.GetCompleted())
            {
                progress.Complete();
                return;
            }

            if (!Started)
            {
                Started = true;

                var task = new Task(() =>
                {
                    try
                    {
                        MakeRequest();
                    }
                    catch (Exception ex)
                    {
                        logger.Error("Error", ex);
                        Terminate();
                    }
                    finally
                    {
                        lock (locker)
                        {
                            progress.Complete();
                        }
                        Publish();
                    }
                }, tokenSource.Token, TaskCreationOptions.LongRunning);

                task.ConfigureAwait(false);
                task.Start();
            }
        }
예제 #3
0
        private WarmUp()
        {
            tokenSource = new CancellationTokenSource();
            TenantId    = CoreContext.TenantManager.GetCurrentTenant().TenantId;

            int instanceCount;

            if (!int.TryParse(ConfigurationManager.AppSettings["web.warmup.count"], out instanceCount))
            {
                instanceCount = 1;
            }

            startupProgresses = new Dictionary <string, StartupProgress>(instanceCount);

            Urls = GetUrlsForRequests();

            progress = new StartupProgress(Urls.Count);

            cacheNotify.Subscribe <KeyValuePair <string, StartupProgress> >(
                (kv, action) =>
            {
                switch (action)
                {
                case CacheNotifyAction.Remove:
                    tokenSource.Cancel();

                    lock (locker)
                    {
                        progress.Complete();
                        Publish();
                    }
                    break;

                case CacheNotifyAction.InsertOrUpdate:
                    if (!startupProgresses.ContainsKey(kv.Key))
                    {
                        startupProgresses.Add(kv.Key, kv.Value);
                    }
                    else
                    {
                        startupProgresses[kv.Key] = kv.Value;
                    }
                    break;
                }
            });

            Publish();
        }
예제 #4
0
        private WarmUp()
        {
            try
            {
                logger = LogManager.GetLogger("ASC");

                int timeout;

                if (!int.TryParse(ConfigurationManagerExtension.AppSettings["web.warmup.timeout"], out timeout))
                {
                    timeout = 15;
                }

                tokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(timeout));

                if (CoreContext.Configuration.Standalone)
                {
                    Tenant = CoreContext.TenantManager.GetTenants().FirstOrDefault();
                }
                else
                {
                    Tenant = CoreContext.TenantManager.GetCurrentTenant(false);
                }


                if (!int.TryParse(ConfigurationManagerExtension.AppSettings["web.warmup.count"], out instanceCount))
                {
                    instanceCount = 1;
                }

                startupProgresses = new Dictionary <string, StartupProgress>(instanceCount);

                Urls = GetUrlsForRequests();

                progress = new StartupProgress(Urls.Count);

                cacheNotify.Subscribe <KeyValuePair <string, StartupProgress> >(
                    (kv, action) =>
                {
                    switch (action)
                    {
                    case CacheNotifyAction.Remove:
                        tokenSource.Cancel();

                        lock (locker)
                        {
                            progress.Complete();
                        }

                        break;

                    case CacheNotifyAction.InsertOrUpdate:
                        if (!startupProgresses.ContainsKey(kv.Key))
                        {
                            startupProgresses.Add(kv.Key, kv.Value);
                        }
                        else
                        {
                            startupProgresses[kv.Key] = kv.Value;
                        }
                        break;
                    }
                });

                Publish();
                successInitialized = true;
            }
            catch (Exception e)
            {
                LogManager.GetLogger("ASC.Web").Error("Warmup error", e);
            }
        }
예제 #5
0
        private WarmUpController()
        {
            try
            {
                logger = LogManager.GetLogger("ASC");

                if (!int.TryParse(ConfigurationManager.AppSettings["web.warmup.timeout"], out timeout))
                {
                    timeout = 15;
                }

                tokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(timeout));
                TenantId    = CoreContext.TenantManager.GetCurrentTenant().TenantId;

                if (!int.TryParse(ConfigurationManager.AppSettings["web.warmup.count"], out instanceCount))
                {
                    instanceCount = 1;
                }

                bool enabled;
                if (!bool.TryParse(ConfigurationManager.AppSettings["web.warmup.enabled"] ?? "false", out enabled))
                {
                    enabled = false;
                }
                try
                {
                    cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
                }
                catch (Exception e)
                {
                    logger.Error("new PerformanceCounter error", e);
                }

                startupProgresses = new Dictionary <string, StartupProgress>(instanceCount);

                Pages     = GetPagesForWarmup();
                WarmUpUrl = GetFullAbsolutePath("~/Warmup.aspx");
                progress  = new StartupProgress(Pages.Count);

                if (CoreContext.Configuration.Standalone)
                {
                    Timer          = new Timer();
                    Timer.Elapsed += Timer_Elapsed;
                    Timer.Interval = TimeSpan.FromMinutes(15).TotalMilliseconds;
                }

                cacheNotify.Subscribe <KeyValuePair <string, StartupProgress> >(
                    (kv, action) =>
                {
                    switch (action)
                    {
                    case CacheNotifyAction.Remove:
                        tokenSource.Cancel();

                        progress.Complete();

                        break;

                    case CacheNotifyAction.InsertOrUpdate:
                        if (!startupProgresses.ContainsKey(kv.Key))
                        {
                            startupProgresses.Add(kv.Key, kv.Value);
                        }
                        else
                        {
                            startupProgresses[kv.Key] = kv.Value;
                        }
                        break;
                    }
                });

                Publish();
                successInitialized = enabled;
            }
            catch (Exception e)
            {
                LogManager.GetLogger("ASC.Web").Error("Warmup error", e);
            }
        }