@@ -29,34 +29,36 @@ public Agent(IConfigSource configSource, IEnvironment environment, IPlanner plan
29
29
30
30
public async Task ReconcileAsync ( CancellationToken token )
31
31
{
32
- Task < ModuleSet > envTask = this . environment . GetModulesAsync ( token ) ;
33
- Task < ModuleSet > configTask = this . configSource . GetModuleSetAsync ( ) ;
34
-
35
- await Task . WhenAll ( envTask , configTask ) ;
36
-
37
- ModuleSet current = envTask . Result ;
38
- ModuleSet desired = configTask . Result ;
32
+ var ( current , agentConfig ) = await TaskEx . WhenAll (
33
+ this . environment . GetModulesAsync ( token ) ,
34
+ this . configSource . GetAgentConfigAsync ( )
35
+ ) ;
39
36
ModuleSet updated = current ;
40
-
41
- ImmutableDictionary < string , IModuleIdentity > identities = ( await this . moduleIdentityLifecycleManager . UpdateModulesIdentity ( desired , current ) )
42
- . ToImmutableDictionary ( p => p . Name ) ;
43
- Plan plan = await this . planner . PlanAsync ( desired , current , identities ) ;
44
37
45
- if ( ! plan . IsEmpty )
38
+ if ( agentConfig != AgentConfig . Empty )
46
39
{
47
- try
40
+ IImmutableDictionary < string , IModuleIdentity > identities = await this . moduleIdentityLifecycleManager . GetModuleIdentities ( agentConfig . ModuleSet , current ) ;
41
+ Plan plan = await this . planner . PlanAsync ( agentConfig . ModuleSet , current , identities ) ;
42
+ if ( ! plan . IsEmpty )
48
43
{
49
- await plan . ExecuteAsync ( token ) ;
50
- updated = await this . environment . GetModulesAsync ( token ) ;
51
- }
52
- catch ( Exception ex )
53
- {
54
- Events . PlanExecutionFailed ( ex ) ;
55
- throw ;
44
+ try
45
+ {
46
+ await plan . ExecuteAsync ( token ) ;
47
+ updated = await this . environment . GetModulesAsync ( token ) ;
48
+ }
49
+ catch ( Exception ex )
50
+ {
51
+ Events . PlanExecutionFailed ( ex ) ;
52
+
53
+ updated = await this . environment . GetModulesAsync ( token ) ;
54
+ await this . reporter . ReportAsync ( token , updated , agentConfig , new DeploymentStatus ( DeploymentStatusCode . Failed , ex . Message ) ) ;
55
+
56
+ throw ;
57
+ }
56
58
}
57
59
}
58
60
59
- await this . reporter . ReportAsync ( updated ) ;
61
+ await this . reporter . ReportAsync ( token , updated , agentConfig , DeploymentStatus . Success ) ;
60
62
}
61
63
62
64
static class Events
@@ -67,7 +69,6 @@ static class Events
67
69
enum EventIds
68
70
{
69
71
AgentCreated = IdStart ,
70
- UpdateDesiredStateFailed ,
71
72
PlanExecutionFailed
72
73
}
73
74
@@ -76,11 +77,6 @@ public static void AgentCreated()
76
77
Log . LogDebug ( ( int ) EventIds . AgentCreated , "Agent Created." ) ;
77
78
}
78
79
79
- public static void UpdateDesiredStateFailed ( )
80
- {
81
- Log . LogError ( ( int ) EventIds . UpdateDesiredStateFailed , "Agent update to desired state failed." ) ;
82
- }
83
-
84
80
public static void PlanExecutionFailed ( Exception ex )
85
81
{
86
82
Log . LogError ( ( int ) EventIds . PlanExecutionFailed , ex , "Agent Plan execution failed." ) ;
0 commit comments