MCPcopy Create free account
hub / github.com/compozy/agh / NewManager

Function NewManager

internal/task/manager.go:244–304  ·  view source on GitHub ↗

NewManager constructs one task-domain manager with the supplied dependencies.

(opts ...Option)

Source from the content-addressed store, hash-verified

242
243// NewManager constructs one task-domain manager with the supplied dependencies.
244func NewManager(opts ...Option) (*Service, error) {
245 options := managerOptions{
246 profileValidation: DefaultExecutionProfileValidationOptions(),
247 forceRecovery: ForceRecoveryOptions{
248 AllowAgentForce: true,
249 RateLimitPerMinute: DefaultForceRunRateLimitPerMinute,
250 },
251 now: func() time.Time {
252 return time.Now().UTC()
253 },
254 newID: store.NewID,
255 starvationAge: DefaultTaskStarvationAge,
256 blockRecurrenceLimit: configdefaults.BlockRecurrenceLimit,
257 }
258 for _, opt := range opts {
259 if opt != nil {
260 opt(&options)
261 }
262 }
263 if options.starvationAge <= 0 {
264 options.starvationAge = DefaultTaskStarvationAge
265 }
266 if options.store == nil {
267 return nil, fmt.Errorf("task: manager store is required")
268 }
269 if options.now == nil {
270 return nil, fmt.Errorf("task: manager clock is required")
271 }
272 if options.newID == nil {
273 return nil, fmt.Errorf("task: manager id generator is required")
274 }
275 if options.cancelGracePeriod < 0 {
276 return nil, fmt.Errorf("task: manager cancel grace period must be zero or positive")
277 }
278 if options.blockRecurrenceLimit < 0 {
279 return nil, fmt.Errorf("task: block recurrence limit must be zero or positive")
280 }
281
282 return &Service{
283 store: options.store,
284 sessions: options.sessions,
285 runtimeViews: options.runtimeViews,
286 inspectReader: options.inspectReader,
287 eventObserver: options.eventObserver,
288 reviewObserver: options.reviewObserver,
289 taskHooks: defaultTaskRunHooks(options.taskHooks),
290 wakeNotifier: defaultWakeNotifier(options.wakeNotifier),
291 channelValidator: options.channelValidator,
292 profileValidation: options.profileValidation,
293 forceRecovery: normalizeForceRecoveryOptions(options.forceRecovery),
294 now: options.now,
295 newID: options.newID,
296 cancelGracePeriod: options.cancelGracePeriod,
297 starvationAge: options.starvationAge,
298 blockRecurrenceLimit: options.blockRecurrenceLimit,
299 forceRateLimiter: newForceRunRateLimiter(),
300 wakeEventIDs: make(map[string]struct{}),
301 wakeEventOrder: make([]string, 0, wakeEventCacheMaxEntries),

Calls 6

defaultTaskRunHooksFunction · 0.85
defaultWakeNotifierFunction · 0.85
newForceRunRateLimiterFunction · 0.85
NowMethod · 0.45