private static void RunTaskOnNewThread(object oTask) { if (oTask == null) { return; } WebTaskManager task = (WebTaskManager)oTask; log.Info("deserialized WebTaskManager task"); // give a little time to make sure the taskqueue was updated after spawning the thread Thread.Sleep(100); // 0.10 seconds task.RunTask(); log.Info("started WebTaskManager task"); }
//public static void RegisterRoutes(RouteCollection routes) //{ // routes.Clear(); // RoutingHandler.Configure(routes); //} //#if!NET35 // private void SetupMonitoring() // { // if (appDomainMonitoringEnabled) // { // AppDomain.MonitoringIsEnabled = true; // } // if (firstChanceExceptionMonitoringEnabled) // { // AppDomain.CurrentDomain.FirstChanceException += (object source, FirstChanceExceptionEventArgs e) => // { // if (HttpContext.Current == null)// If no context available, ignore it // return; // if (HttpContext.Current.Items[RequestExceptionKey] == null) // HttpContext.Current.Items[RequestExceptionKey] = new RequestException { Exceptions = new List<Exception>() }; // (HttpContext.Current.Items[RequestExceptionKey] as RequestException).Exceptions.Add(e.Exception); // }; // } // } // private void CaptureMonitoringData() // { // if (!firstChanceExceptionMonitoringEnabled) { return; } // if (Context.Items[RequestExceptionKey] != null) // { // //Only add the request if atleast one exception is raised // var reqExc = Context.Items[RequestExceptionKey] as RequestException; // reqExc.Url = Request.Url.AbsoluteUri; // Application.Lock(); // if (Application["AllExc"] == null) // Application["AllExc"] = new List<RequestException>(); // (Application["AllExc"] as List<RequestException>).Add(reqExc); // Application.UnLock(); // } // } //#endif 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); }
public static void StartOrResumeTasks(bool appWasRestarted) { if (WebConfigSettings.DisableTaskQueue) { return; } List<TaskQueue> unfinishedTasks; SiteSettings siteSettings = null; try { TaskQueue.DeleteCompleted(); // the default is false and it may be problematic to try and use this as true // because the app start event only fires 1 time not 1 time per site if (WebConfigSettings.UsePerSiteTaskQueue) { // this also doesn't work in IIS 7 integrated pipeline mode because HttpContext is null siteSettings = CacheHelper.GetCurrentSiteSettings(); } if ((WebConfigSettings.UsePerSiteTaskQueue) && (siteSettings != null)) { unfinishedTasks = TaskQueue.GetUnfinished(siteSettings.SiteGuid); } else { unfinishedTasks = TaskQueue.GetUnfinished(); } if (WebTaskManagerIsRunning(unfinishedTasks, appWasRestarted)) return; if ((appWasRestarted) && (unfinishedTasks.Count == 0)) return; WebTaskManager taskManager = new WebTaskManager(); taskManager.QueueTask(); taskManager.StartTask(); } catch (DbException ex) { log.Error(ex); } catch (InvalidOperationException ex) { log.Error(ex); } catch (Exception ex) { // hate to trap System.Exception but SqlCeException doe snot inherit from DbException as it should if (DatabaseHelper.DBPlatform() != "SqlCe") { throw; } log.Error(ex); } }
public static void StartOrResumeTasks(bool appWasRestarted) { if (WebConfigSettings.DisableTaskQueue) { return; } List <TaskQueue> unfinishedTasks; SiteSettings siteSettings = null; try { TaskQueue.DeleteCompleted(); // the default is false and it may be problematic to try and use this as true // because the app start event only fires 1 time not 1 time per site if (WebConfigSettings.UsePerSiteTaskQueue) { // this also doesn't work in IIS 7 integrated pipeline mode because HttpContext is null siteSettings = CacheHelper.GetCurrentSiteSettings(); } if ((WebConfigSettings.UsePerSiteTaskQueue) && (siteSettings != null)) { unfinishedTasks = TaskQueue.GetUnfinished(siteSettings.SiteGuid); } else { unfinishedTasks = TaskQueue.GetUnfinished(); } if (WebTaskManagerIsRunning(unfinishedTasks, appWasRestarted)) { return; } if ((appWasRestarted) && (unfinishedTasks.Count == 0)) { return; } WebTaskManager taskManager = new WebTaskManager(); taskManager.QueueTask(); taskManager.StartTask(); } catch (DbException ex) { log.Error(ex); } catch (InvalidOperationException ex) { log.Error(ex); } catch (Exception ex) { // hate to trap System.Exception but SqlCeException doe snot inherit from DbException as it should if (DatabaseHelper.DBPlatform() != "SqlCe") { throw; } log.Error(ex); } }