Skip to content

Commit 33a4b58

Browse files
committed
go/runtime/registry/notifier: Refactor ROFL notifier
1 parent c528cf5 commit 33a4b58

9 files changed

Lines changed: 307 additions & 155 deletions

File tree

.changelog/6263.trivial.md

Whitespace-only changes.

go/runtime/registry/handler.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type RuntimeHostHandlerEnvironment interface {
4040

4141
// GetRuntimeRegistry returns the runtime registry.
4242
GetRuntimeRegistry() Registry
43+
44+
// GetROFLNotifier returns the ROFL notifier.
45+
GetROFLNotifier() (*ROFLNotifier, error)
4346
}
4447

4548
// RuntimeHostHandler is a runtime host handler suitable for compute runtimes. It provides the
@@ -124,7 +127,11 @@ func (h *runtimeHostHandler) Handle(ctx context.Context, rq *protocol.Body) (*pr
124127
func (h *runtimeHostHandler) NewSubHandler(comp *bundle.ExplodedComponent) (host.RuntimeHandler, error) {
125128
switch comp.Kind {
126129
case component.ROFL:
127-
return newSubHandlerROFL(comp, h)
130+
roflNotifier, err := h.env.GetROFLNotifier()
131+
if err != nil {
132+
return nil, err
133+
}
134+
return newSubHandlerROFL(comp, h, roflNotifier)
128135
default:
129136
return nil, fmt.Errorf("cannot create sub-handler for component '%s'", comp.Kind)
130137
}

go/runtime/registry/handler_rofl.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ type roflHostHandler struct {
3636
comp *bundle.ExplodedComponent
3737
comps map[component.ID]host.Runtime
3838

39-
client runtimeClient.RuntimeClient
40-
eventNotifier *roflEventNotifier
39+
client runtimeClient.RuntimeClient
40+
roflNotifier *ROFLNotifier
4141

4242
logger *logging.Logger
4343
}
4444

45-
func newSubHandlerROFL(comp *bundle.ExplodedComponent, parent *runtimeHostHandler) (*roflHostHandler, error) {
45+
func newSubHandlerROFL(comp *bundle.ExplodedComponent, parent *runtimeHostHandler, roflNotifier *ROFLNotifier) (*roflHostHandler, error) {
4646
client, err := parent.env.GetRuntimeRegistry().Client()
4747
if err != nil {
4848
return nil, err
@@ -53,13 +53,13 @@ func newSubHandlerROFL(comp *bundle.ExplodedComponent, parent *runtimeHostHandle
5353
With("component_id", comp.ID())
5454

5555
return &roflHostHandler{
56-
parent: parent,
57-
id: comp.ID(),
58-
comp: comp,
59-
comps: make(map[component.ID]host.Runtime),
60-
client: client,
61-
eventNotifier: newROFLEventNotifier(parent.runtime, client, logger),
62-
logger: logger,
56+
parent: parent,
57+
id: comp.ID(),
58+
comp: comp,
59+
comps: make(map[component.ID]host.Runtime),
60+
client: client,
61+
roflNotifier: roflNotifier,
62+
logger: logger,
6363
}, nil
6464
}
6565

@@ -74,7 +74,7 @@ func (rh *roflHostHandler) AttachRuntime(id component.ID, rt host.Runtime) error
7474
if id != rh.id {
7575
return nil
7676
}
77-
return rh.eventNotifier.AttachRuntime(rt)
77+
return nil
7878
}
7979

8080
// getLocalStorageKey returns a properly namespaced version of the local storage key.
@@ -254,13 +254,15 @@ func (rh *roflHostHandler) handleHostSubmitTx(
254254
}
255255

256256
func (rh *roflHostHandler) handleHostRegisterNotify(
257-
ctx context.Context,
257+
_ context.Context,
258258
rq *protocol.HostRegisterNotifyRequest,
259259
) (*protocol.Empty, error) {
260260
// Subscribe to event notifications.
261-
if err := rh.eventNotifier.RegisterNotify(ctx, rq); err != nil {
262-
return nil, err
261+
nfs := &rofl.Notifications{
262+
Blocks: rq.RuntimeBlock,
263+
Events: rq.RuntimeEvent.Tags,
263264
}
265+
rh.roflNotifier.register(rh.id, nfs)
264266

265267
return &protocol.Empty{}, nil
266268
}

go/runtime/registry/notifier.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ const (
3030
queueKeyManagerStatus = "key-manager/status"
3131
queueKeyManagerQuotePolicy = "key-manager/quote-policy"
3232
queueConsensusSync = "consensus-sync"
33+
queueROFLBlock = "rofl/block"
34+
queueROFLTags = "rofl/tags"
35+
queueROFLConfig = "rofl/config"
3336
)
3437

3538
const (

0 commit comments

Comments
 (0)