public void Process(ScheduledTaskContext context) { if (context.Task.TaskType.StartsWith(UPDATEVALUES_TASK + "_")) { _sweepGenerator.Terminate(); try { // Task name is something like HiddenStringFieldValueUpdate_ContentType_PartName_FieldName var partFieldName = context.Task.TaskType.Split('_'); if (partFieldName.Length == 5) { var typeName = partFieldName[1]; var partName = partFieldName[2]; var fieldName = partFieldName[3]; HiddenStringFieldUpdateProcessVariant updateType; var validUpdate = Enum.TryParse(partFieldName[4], out updateType); if (validUpdate) { ProcessInternal(updateType, typeName, partName, fieldName); } } } catch (Exception ex) { Logger.Error(ex, "Update Hidden String Values Error: " + context.Task.TaskType + " - " + ex.Message); } finally { _sweepGenerator.Activate(); } } }
public void Terminate() { SafelyTerminate(() => { using (var events = _eventsFactory()) { SafelyTerminate(() => events.Value.Terminating()); } }); SafelyTerminate(() => _sweepGenerator.Terminate()); }
public void Terminate() { SafelyTerminate(() => { using (var scope = _workContextAccessor.CreateWorkContextScope()) { using (var events = scope.Resolve <Owned <IOrchardShellEvents> >()) { SafelyTerminate(() => events.Value.Terminating()); } } }); SafelyTerminate(() => _sweepGenerator.Terminate()); }
public void Terminate() { using (var events = _eventsFactory()) { try { events.Value.Terminating(); } catch { // ignore exceptions while terminating the application } _sweepGenerator.Terminate(); } }
/// <summary> /// 终止外壳。 /// </summary> public void Terminate() { SafelyTerminate(() => { using (var scope = _lifetimeScope.CreateWorkContextScope()) { foreach (var shellEventse in scope.Resolve <IEnumerable <IShellEvents> >()) { shellEventse.Terminating(); } } }); SafelyTerminate(() => _sweepGenerator.Terminate()); }
public override void Execute(ImportActionContext context) { var recipeDocument = context.RecipeDocument ?? RecipeDocument; if (recipeDocument == null) { return; } // Give each execution step a chance to augment the recipe step before it will be scheduled. PrepareRecipe(recipeDocument); // Sets the request timeout to a configurable amount of seconds to give enough time to execute custom recipes. if (_orchardServices.WorkContext.HttpContext != null) { _orchardServices.WorkContext.HttpContext.Server.ScriptTimeout = RecipeExecutionTimeout; } // Suspend background task execution. _sweepGenerator.Terminate(); // Import or setup using the specified recipe. var executionId = ResetSite ? Setup(recipeDocument) : ExecuteRecipe(recipeDocument); if (executionId == null) { _orchardServices.Notifier.Warning(T("The recipe contained no steps. No work was scheduled.")); _sweepGenerator.Activate(); return; } // Resume background tasks once import/setup completes. var recipe = _recipeParser.ParseRecipe(recipeDocument); var activateSweepGeneratorStep = new RecipeStep(Guid.NewGuid().ToString("N"), recipe.Name, "ActivateSweepGenerator", new XElement("ActivateSweepGenerator")); _recipeStepQueue.Enqueue(executionId, activateSweepGeneratorStep); _recipeStepResultRepository.Create(new RecipeStepResultRecord { ExecutionId = executionId, RecipeName = recipe.Name, StepId = activateSweepGeneratorStep.Id, StepName = activateSweepGeneratorStep.Name }); context.ExecutionId = executionId; context.RecipeDocument = recipeDocument; }
public void Process(ScheduledTaskContext context) { string taskTypeStr = context.Task.TaskType; if (taskTypeStr.IndexOf(Constants.TaskTypeBase) == 0) { try { //For some reason, querying the db for the records related to the task returns null //Hence, we placed the part id in the TaskType. int pid = int.Parse(taskTypeStr.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries).Last()); ScheduledTaskPart part = (ScheduledTaskPart)_orchardServices.ContentManager.Get <ScheduledTaskPart>(pid); if (part == null) { Logger.Error("Laser.TaskScheduler was unable to identify and process the task of type " + taskTypeStr); } else { //Trigger the event //get the signal name for from the part to track edits that may have been done. if (part.ExecutionType == ExecutionTypes.WorkFlow) { _workflowManager.TriggerEvent( SignalActivity.SignalEventName, context.Task.ContentItem, () => new Dictionary <string, object> { { "Content", context.Task.ContentItem }, { SignalActivity.SignalEventName, part.SignalName } } ); } else { if (part.ExecutionType == ExecutionTypes.Razor) { if (part.LongTask) { _sweepGenerator.Terminate(); try { var result = _razorExecuteService.Execute(part.SignalName, context.Task.ContentItem, new Dictionary <string, object>() { { "Content", context.Task.ContentItem }, { SignalActivity.SignalEventName, part.SignalName } }).Trim(); } catch (Exception ex) { Logger.Error(ex, "ScheduledTaskTasksHandler -> Long Task Error on " + taskTypeStr + ex.Message); } finally { if (part.LongTask) { _sweepGenerator.Activate(); } } } else { var result = _razorExecuteService.Execute(part.SignalName, context.Task.ContentItem, new Dictionary <string, object>() { { "Content", context.Task.ContentItem }, { SignalActivity.SignalEventName, part.SignalName } }).Trim(); } } } if (part.Autodestroy) { var sc = new ScheduledTaskViewModel(part); sc.Delete = true; var list = new List <ScheduledTaskViewModel>(); list.Add(sc); _scheduledTaskService.UpdateRecords(list); } else { //if the part has periodicity and it was not unscheduled, we may reschedule the task if (part.PeriodicityTime > 0 && part.RunningTaskId > 0) { //define tasktype string newTaskTypeStr = Constants.TaskTypeBase + "_" + part.SignalName + "_" + part.Id; ContentItem ci = null; if (part.ContentItemId > 0) { ci = _orchardServices.ContentManager.Get(part.ContentItemId); } DateTime scheduleTime = _scheduledTaskService.ComputeNextScheduledTime(part); _taskManager.CreateTask(newTaskTypeStr, scheduleTime, ci); part.RunningTaskId = _repoTasks.Get(str => str.TaskType.Equals(newTaskTypeStr)).Id; } else { part.RunningTaskId = 0; } } } } catch (Exception ex) { Logger.Error(ex, "ScheduledTaskTasksHandler -> Error on " + taskTypeStr + " id= " + context.Task.ContentItem + ex.Message); } } }