Skip to content

Commit

Permalink
capabilities: Only start/stop the mock producer when capability is in…
Browse files Browse the repository at this point in the history
… use
  • Loading branch information
archseer committed Aug 6, 2024
1 parent 3aae748 commit 8522609
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions core/capabilities/streams/mock_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ func RegisterMockTrigger(lggr logger.Logger, capRegistry core.CapabilitiesRegist
return nil, err
}

producer := NewMockDataProducer(trigger, lggr)
if err := producer.Start(ctx); err != nil {
return nil, err
}

return trigger, nil
}

Expand Down Expand Up @@ -117,8 +112,9 @@ type MockTriggerService struct {
lggr logger.Logger

//
meta datastreams.SignersMetadata
signers []*ecdsa.PrivateKey
meta datastreams.SignersMetadata
signers []*ecdsa.PrivateKey
producer *mockDataProducer
//
}

Expand Down Expand Up @@ -214,6 +210,13 @@ func (o *MockTriggerService) RegisterTrigger(ctx context.Context, req capabiliti
workflowID: wid,
config: *config,
}

// Only start the producer once a workflow is registered
o.producer = NewMockDataProducer(o, o.lggr)
if err := o.producer.Start(ctx); err != nil {
return nil, err
}

return ch, nil
}

Expand All @@ -235,6 +238,12 @@ func (o *MockTriggerService) UnregisterTrigger(ctx context.Context, req capabili
}
close(subscriber.ch)
delete(o.subscribers, triggerID)
if len(o.subscribers) == 0 {
if err := o.producer.Close(); err != nil {
return err
}
o.producer = nil
}
return nil
}

Expand Down

0 comments on commit 8522609

Please sign in to comment.