private static void RunTaskOnNewTopic(object topicSleepTask)
        {
            if (topicSleepTask == null)
            {
                return;
            }
            AppKeepAliveTask task = (AppKeepAliveTask)topicSleepTask;

            log.Info("deserialized AppKeepAliveTask task");

            // give a little time to make sure the taskqueue was updated after spawning the topic
            Thread.Sleep(10000); // 10 seconds

            task.RunTask();

            log.Info("started AppKeepAliveTask task");
        }
Esempio n. 2
0
        private void StartOrResumeTasks()
        {
            // NOTE: In IIS 7 using integrated mode, HttpContext.Current will always be null in Application_Start
            // http://weblogs.asp.net/jgaylord/archive/2008/09/04/iis7-integrated-mode-and-global-asax.aspx
            if (WebConfigSettings.UseAppKeepAlive)
            {
                AppKeepAliveTask keepAlive;
                try
                {
                    try
                    {
                        if ((HttpContext.Current != null) && (HttpContext.Current.Request != null))
                        {
                            keepAlive = new AppKeepAliveTask();
                            keepAlive.UrlToRequest      = WebUtils.GetSiteRoot();
                            keepAlive.MaxRunTimeMinutes = WebConfigSettings.AppKeepAliveMaxRunTimeMinutes;
                            keepAlive.MinutesToSleep    = WebConfigSettings.AppKeepAliveSleepMinutes;
                            keepAlive.QueueTask();
                        }
                    }
                    catch (HttpException)
                    {
                        //this error will be thrown when using IIS 7 Integrated pipeline mode
                        //since we have no context.Request to get the site root, in IIS 7 Integrated pipeline mode
                        //we need to use an additional config setting to get the url to request for keep alive
                        if (WebConfigSettings.AppKeepAliveUrl.Length > 0)
                        {
                            keepAlive = new AppKeepAliveTask();
                            keepAlive.UrlToRequest      = WebConfigSettings.AppKeepAliveUrl;
                            keepAlive.MaxRunTimeMinutes = WebConfigSettings.AppKeepAliveMaxRunTimeMinutes;
                            keepAlive.MinutesToSleep    = WebConfigSettings.AppKeepAliveSleepMinutes;
                            keepAlive.QueueTask();
                        }
                    }
                }
                catch (Exception ex)
                {
                    // if a new installation the table will not exist yet so just log and swallow
                    log.Error(ex);
                }
            }


            WebTaskManager.StartOrResumeTasks(true);
        }