Skip to content

Commit

Permalink
Addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kidambisrinivas committed Sep 27, 2024
1 parent a4a7f0e commit 1cc9ce0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/capabilities/triggers/logevent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s *TriggerService) RegisterTrigger(ctx context.Context, req capabilities.T
if err != nil {
return nil, fmt.Errorf("LogEventTrigger %v", err)
}
s.lggr.Debugw("RegisterTrigger", "triggerId", req.TriggerID)
s.lggr.Infow("RegisterTrigger", "triggerId", req.TriggerID, "WorkflowExecutionID", req.Metadata.WorkflowExecutionID)
return respCh, nil
}

Expand All @@ -121,7 +121,7 @@ func (s *TriggerService) UnregisterTrigger(ctx context.Context, req capabilities
trigger.Stop()
// Remove from triggers context
s.triggers.Delete(req.TriggerID)
s.lggr.Debugw("UnregisterTrigger", "triggerId", req.TriggerID)
s.lggr.Infow("UnregisterTrigger", "triggerId", req.TriggerID, "WorkflowExecutionID", req.Metadata.WorkflowExecutionID)
return nil
}

Expand Down
13 changes: 13 additions & 0 deletions core/capabilities/triggers/logevent/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"sync"
"time"

"github.com/smartcontractkit/chainlink-common/pkg/capabilities"
Expand Down Expand Up @@ -43,6 +44,7 @@ type logEventTrigger struct {
logEventConfig Config
ticker *time.Ticker
done chan bool
wg sync.WaitGroup
}

// Construct for logEventTrigger struct
Expand Down Expand Up @@ -156,7 +158,9 @@ func (l *logEventTrigger) Listen(ctx context.Context) {
}
for _, log := range logs {
triggerResp := createTriggerResponse(log, l.logEventConfig.Version(ID))
l.wg.Add(1)
go func(resp capabilities.TriggerResponse) {
defer l.wg.Done()
l.ch <- resp
}(triggerResp)
cursor = log.Cursor
Expand Down Expand Up @@ -184,6 +188,15 @@ func createTriggerResponse(log types.Sequence, version string) capabilities.Trig

// Stop contract event listener for the current contract
func (l *logEventTrigger) Stop() {
l.lggr.Infow("Closing trigger server for (waiting for waitGroup)", "ChainID", l.logEventConfig.ChainID,
"ContractName", l.reqConfig.ContractName,
"ContractAddress", l.reqConfig.ContractAddress,
"ContractEventName", l.reqConfig.ContractEventName)
l.wg.Wait()
close(l.ch)
l.done <- true
l.lggr.Infow("Closed trigger server for", "ChainID", l.logEventConfig.ChainID,
"ContractName", l.reqConfig.ContractName,
"ContractAddress", l.reqConfig.ContractAddress,
"ContractEventName", l.reqConfig.ContractEventName)
}

0 comments on commit 1cc9ce0

Please sign in to comment.