allow RecipeManager to affect execution timeout (#8572)

Co-authored-by: matteo.piovanelli <matteo.piovanelli@laser-group.com>
This commit is contained in:
Andrea Piovanelli
2022-06-17 08:51:25 +02:00
committed by GitHub
parent f161693d52
commit 9f37c23dd7

View File

@@ -12,17 +12,38 @@ namespace Orchard.Recipes.Services {
private readonly IRecipeScheduler _recipeScheduler;
private readonly IRecipeExecuteEventHandler _recipeExecuteEventHandler;
private readonly IRepository<RecipeStepResultRecord> _recipeStepResultRecordRepository;
private readonly IWorkContextAccessor _workContextAccessor;
public RecipeManager(
IRecipeStepQueue recipeStepQueue,
IRecipeScheduler recipeScheduler,
IRecipeExecuteEventHandler recipeExecuteEventHandler,
IRepository<RecipeStepResultRecord> recipeStepResultRecordRepository) {
IRepository<RecipeStepResultRecord> recipeStepResultRecordRepository,
IWorkContextAccessor workContextAccessor) {
_recipeStepQueue = recipeStepQueue;
_recipeScheduler = recipeScheduler;
_recipeExecuteEventHandler = recipeExecuteEventHandler;
_recipeStepResultRecordRepository = recipeStepResultRecordRepository;
_workContextAccessor = workContextAccessor;
RecipeExecutionTimeout = 600;
}
public int RecipeExecutionTimeout {
get; set;
// The public setter allows injecting this from Sites.MyTenant.Config or Sites.config, by using
// an AutoFac component:
/*
<component instance-scope="per-lifetime-scope"
type="Orchard.Recipes.Services.RecipeManager, Orchard.Recipes.Services"
service="Orchard.Recipes.Services.RecipeManager">
<properties>
<property name="RecipeExecutionTimeout" value="600" />
</properties>
</component>
*/
}
public string Execute(Recipe recipe) {
@@ -35,6 +56,12 @@ namespace Orchard.Recipes.Services {
return null;
}
// Sets the request timeout to a configurable amount of seconds to give enough time to execute custom recipes.
var workContext = _workContextAccessor.GetContext();
if (workContext?.HttpContext != null) {
workContext.HttpContext.Server.ScriptTimeout = RecipeExecutionTimeout;
}
var executionId = Guid.NewGuid().ToString("n");
ThreadContext.Properties["ExecutionId"] = executionId;