Skip to content

Commit ea2ed49

Browse files
intel352claude
andauthored
refactor: replace concrete type switch with ExecutionTrackerSetter interface (#62) (#119)
Define an ExecutionTrackerSetter interface in cmd/server/main.go alongside the other local server interfaces. The loop in registerPostStartServices now uses a single interface assertion instead of a type switch on *module.QueryHandler and *module.CommandHandler, so new module types that need execution tracking only need to implement SetExecutionTracker — no server changes required. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 06ecdab commit ea2ed49

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

cmd/server/main.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ type executionTrackerIface interface {
237237
SetEventStoreRecorder(r module.EventRecorder)
238238
}
239239

240+
// ExecutionTrackerSetter is implemented by any module that accepts an
241+
// ExecutionTrackerProvider. Using this interface in place of a concrete-type
242+
// switch means the server does not need to be modified when new module types
243+
// require execution tracking.
244+
type ExecutionTrackerSetter interface {
245+
SetExecutionTracker(module.ExecutionTrackerProvider)
246+
}
247+
240248
// runtimeLifecycle manages the lifecycle of running workflow instances.
241249
type runtimeLifecycle interface {
242250
StopAll(ctx context.Context) error
@@ -945,10 +953,7 @@ func (app *serverApp) registerPostStartServices(logger *slog.Logger) error {
945953
}
946954

947955
for _, svc := range engine.GetApp().SvcRegistry() {
948-
switch h := svc.(type) {
949-
case *module.QueryHandler:
950-
h.SetExecutionTracker(app.services.executionTracker)
951-
case *module.CommandHandler:
956+
if h, ok := svc.(ExecutionTrackerSetter); ok {
952957
h.SetExecutionTracker(app.services.executionTracker)
953958
}
954959
}

0 commit comments

Comments
 (0)