Exemplo n.º 1
0
 private void EnqueueRecipe(string executionId, Recipe recipe)
 {
     foreach (var recipeStep in recipe.RecipeSteps)
     {
         _recipeStepQueue.Enqueue(executionId, recipeStep);
         _recipeStepResultRecordRepository.Create(new RecipeStepResultRecord {
             ExecutionId = executionId,
             RecipeName  = recipe.Name,
             StepId      = recipeStep.Id,
             StepName    = recipeStep.Name
         });
     }
 }
        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;
        }
Exemplo n.º 3
0
        public string Execute(Recipe recipe)
        {
            if (recipe == null)
            {
                return(null);
            }

            var executionId = Guid.NewGuid().ToString("n");

            _recipeJournal.ExecutionStart(executionId);

            foreach (var recipeStep in recipe.RecipeSteps)
            {
                _recipeStepQueue.Enqueue(executionId, recipeStep);
            }
            _recipeScheduler.ScheduleWork(executionId);

            return(executionId);
        }
        public string Execute(Recipe recipe)
        {
            if (recipe == null)
            {
                throw new ArgumentNullException("recipe");
            }

            if (!recipe.RecipeSteps.Any())
            {
                Logger.Information("Recipe '{0}' contains no steps. No work has been scheduled.");
                return(null);
            }

            var executionId = Guid.NewGuid().ToString("n");

            ThreadContext.Properties["ExecutionId"] = executionId;

            try {
                Logger.Information("Executing recipe '{0}'.", recipe.Name);
                _recipeExecuteEventHandler.ExecutionStart(executionId, recipe);

                foreach (var recipeStep in recipe.RecipeSteps)
                {
                    _recipeStepQueue.Enqueue(executionId, recipeStep);
                    _recipeStepResultRecordRepository.Create(new RecipeStepResultRecord {
                        ExecutionId = executionId,
                        RecipeName  = recipe.Name,
                        StepId      = recipeStep.Id,
                        StepName    = recipeStep.Name
                    });
                }
                _recipeScheduler.ScheduleWork(executionId);

                return(executionId);
            }
            finally {
                ThreadContext.Properties["ExecutionId"] = null;
            }
        }