-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.go
More file actions
100 lines (90 loc) · 3.08 KB
/
plugin.go
File metadata and controls
100 lines (90 loc) · 3.08 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
// Package timeline provides a plugin that registers the timeline.service
// module type for config-driven timeline/replay handler initialization.
package timeline
import (
"github.com/GoCodeAlone/modular"
"github.com/GoCodeAlone/workflow/module"
"github.com/GoCodeAlone/workflow/plugin"
evstore "github.com/GoCodeAlone/workflow/store"
)
// Plugin registers the timeline.service module type.
type Plugin struct {
plugin.BaseEnginePlugin
}
// New creates a new timeline plugin.
func New() *Plugin {
return &Plugin{
BaseEnginePlugin: plugin.BaseEnginePlugin{
BaseNativePlugin: plugin.BaseNativePlugin{
PluginName: "timeline",
PluginVersion: "1.0.0",
PluginDescription: "Timeline and replay service module for execution visualization",
},
Manifest: plugin.PluginManifest{
Name: "timeline",
Version: "1.0.0",
Author: "GoCodeAlone",
Description: "Timeline and replay service module for execution visualization",
Tier: plugin.TierCore,
ModuleTypes: []string{"timeline.service"},
},
},
}
}
// ModuleFactories returns the module factories for the timeline service.
func (p *Plugin) ModuleFactories() map[string]plugin.ModuleFactory {
return map[string]plugin.ModuleFactory{
"timeline.service": func(name string, config map[string]any) modular.Module {
// The timeline module needs an EventStore. It discovers the event
// store from the config's "event_store" key, which should reference
// a service name registered by an eventstore.service module.
// At factory time we don't have the Application yet, so we use a
// deferred-init approach: create a stub that resolves at Init().
return &deferredTimelineModule{
name: name,
eventStoreName: stringFromConfig(config, "event_store", "admin-event-store"),
}
},
}
}
// deferredTimelineModule resolves the event store dependency at Init() time.
type deferredTimelineModule struct {
name string
eventStoreName string
inner *module.TimelineServiceModule
}
func (m *deferredTimelineModule) Name() string { return m.name }
func (m *deferredTimelineModule) Init(app modular.Application) error {
// Look up the event store from the service registry
var store *evstore.SQLiteEventStore
if err := app.GetService(m.eventStoreName, &store); err != nil || store == nil {
// Fallback: try to find any EventStore in the registry
for _, svc := range app.SvcRegistry() {
if es, ok := svc.(*evstore.SQLiteEventStore); ok {
store = es
break
}
}
}
if store == nil {
// No event store available — the module will provide stub handlers
return nil
}
m.inner = module.NewTimelineServiceModule(m.name, store)
return nil
}
func (m *deferredTimelineModule) ProvidesServices() []modular.ServiceProvider {
if m.inner != nil {
return m.inner.ProvidesServices()
}
return nil
}
func (m *deferredTimelineModule) RequiresServices() []modular.ServiceDependency {
return nil
}
func stringFromConfig(config map[string]any, key, defaultVal string) string {
if v, ok := config[key].(string); ok && v != "" {
return v
}
return defaultVal
}