-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathstartup-orchestrator.ts
More file actions
149 lines (129 loc) · 3.42 KB
/
Copy pathstartup-orchestrator.ts
File metadata and controls
149 lines (129 loc) · 3.42 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { Plugin } from './plugin-validator.js';
/**
* IStartupOrchestrator - Startup Orchestrator Interface
*
* Abstract interface for orchestrating plugin startup with advanced features:
* - Timeout handling
* - Rollback on failure
* - Health checks
* - Startup metrics
*
* Extracted from PluginLoader to follow Single Responsibility Principle.
*/
/**
* Startup options for orchestration
*/
export interface StartupOptions {
/**
* Maximum time (ms) to wait for each plugin to start
* @default 30000 (30 seconds)
*/
timeout?: number;
/**
* Whether to rollback (destroy) already-started plugins on failure
* @default true
*/
rollbackOnFailure?: boolean;
/**
* Whether to run health checks after startup
* @default false
*/
healthCheck?: boolean;
/**
* Whether to run plugins in parallel (if dependencies allow)
* @default false (sequential startup)
*/
parallel?: boolean;
/**
* Custom context to pass to plugin lifecycle methods
*/
context?: any;
}
/**
* Plugin startup result
*/
export interface PluginStartupResult {
/**
* Plugin that was started
*/
plugin: Plugin;
/**
* Whether startup was successful
*/
success: boolean;
/**
* Time taken to start (milliseconds)
*/
duration: number;
/**
* Error if startup failed
*/
error?: Error;
/**
* Health status after startup (if healthCheck enabled)
*/
health?: HealthStatus;
}
/**
* Health status for a plugin
*/
export interface HealthStatus {
/**
* Whether the plugin is healthy
*/
healthy: boolean;
/**
* Health check timestamp
*/
timestamp: number;
/**
* Optional health details
*/
details?: Record<string, any>;
/**
* Optional error message if unhealthy
*/
message?: string;
}
/**
* IStartupOrchestrator - Plugin startup orchestration interface
*/
export interface IStartupOrchestrator {
/**
* Orchestrate startup of multiple plugins
* Handles timeout, rollback, and health checks
* @param plugins - Array of plugins to start (in dependency order)
* @param options - Startup options
* @returns Promise resolving to startup results for each plugin
*/
orchestrateStartup(
plugins: Plugin[],
options: StartupOptions
): Promise<PluginStartupResult[]>;
/**
* Rollback (destroy) a set of plugins
* Used when startup fails and rollback is enabled
* @param startedPlugins - Plugins that were successfully started
* @returns Promise that resolves when rollback is complete
*/
rollback(startedPlugins: Plugin[]): Promise<void>;
/**
* Check health of a single plugin
* @param plugin - Plugin to check
* @returns Promise resolving to health status
*/
checkHealth(plugin: Plugin): Promise<HealthStatus>;
/**
* Wait for a plugin to start with timeout
* @param plugin - Plugin to start
* @param context - Plugin context
* @param timeoutMs - Maximum time to wait (milliseconds)
* @returns Promise resolving when plugin starts or rejecting on timeout
*/
startWithTimeout?(
plugin: Plugin,
context: any,
timeoutMs: number
): Promise<void>;
}