-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathRecipeManager.cs
More file actions
63 lines (54 loc) · 2.37 KB
/
RecipeManager.cs
File metadata and controls
63 lines (54 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Linq;
using log4net;
using Orchard.Data;
using Orchard.Logging;
using Orchard.Recipes.Events;
using Orchard.Recipes.Models;
namespace Orchard.Recipes.Services {
public class RecipeManager : Component, IRecipeManager {
private readonly IRecipeStepQueue _recipeStepQueue;
private readonly IRecipeScheduler _recipeScheduler;
private readonly IRecipeExecuteEventHandler _recipeExecuteEventHandler;
private readonly IRepository<RecipeStepResultRecord> _recipeStepResultRecordRepository;
public RecipeManager(
IRecipeStepQueue recipeStepQueue,
IRecipeScheduler recipeScheduler,
IRecipeExecuteEventHandler recipeExecuteEventHandler,
IRepository<RecipeStepResultRecord> recipeStepResultRecordRepository) {
_recipeStepQueue = recipeStepQueue;
_recipeScheduler = recipeScheduler;
_recipeExecuteEventHandler = recipeExecuteEventHandler;
_recipeStepResultRecordRepository = recipeStepResultRecordRepository;
}
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;
}
}
}
}