Skip to content

Commit

Permalink
docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
MStreet3 committed Nov 10, 2024
1 parent d495624 commit 38ebd33
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 83 deletions.
2 changes: 1 addition & 1 deletion core/services/chainlink/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
nil,
nil,
nil,
syncer.ContractEventPollerConfig{},
"",
)
srvcs = append(srvcs, workflowRegistrySyncer)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ func Test_SecretsWorker(t *testing.T) {
}
contractName = "WorkflowRegistry"
eventName = "WorkflowForceUpdateSecretsRequestedV1"
giveCfg = syncer.ContractEventPollerConfig{
ContractName: contractName,
ContractEventName: eventName,
QueryCount: 20,
}
)

// fill ID with randomd data
Expand All @@ -64,7 +59,6 @@ func Test_SecretsWorker(t *testing.T) {
require.NoError(t, err)

lggr.Infof("deployed workflow registry at %s\n", wfRegistryAddr.Hex())
giveCfg.ContractAddress = wfRegistryAddr.Hex()

// Build the ContractReader config
contractReaderCfg := evmtypes.ChainReaderConfig{
Expand All @@ -90,8 +84,6 @@ func Test_SecretsWorker(t *testing.T) {
contractReader, err := backendTH.NewContractReader(ctx, t, contractReaderCfgBytes)
require.NoError(t, err)

giveCfg.StartBlockNum = uint64(0)

// Seed the DB
gotID, err := orm.Update(ctx, giveSecretsURL, giveContents)
require.NoError(t, err)
Expand All @@ -110,7 +102,7 @@ func Test_SecretsWorker(t *testing.T) {
orm,
contractReader,
fetcherFn,
giveCfg,
wfRegistryAddr.Hex(),
syncer.WithTicker(giveTicker),
)

Expand Down
18 changes: 17 additions & 1 deletion core/services/workflows/syncer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (
)

type Handler interface {
// Handle processes the event. Fails if the event type is not supported.
Handle(context.Context, WorkflowRegistryEvent) error
}

// eventHandler is a map of event types to their respective handlers that implements Handler.
type eventHandler struct {
handlers map[WorkflowRegistryEventType]Handler
}

// newEventHandler returns a new eventHandler with a map of event types to their respective handlers.
func newEventHandler(
lggr logger.Logger,
orm ORM,
Expand Down Expand Up @@ -49,10 +52,16 @@ func newForceUpdateSecretsHandler(lggr logger.Logger, orm ORM, gateway FetcherFu
}
}

// Handle processes the ForceUpdateSecretsEvent by fetching the secrets from the URL for a given event
// and updating the local state.
func (h *forceUpdateSecretsHandler) Handle(
ctx context.Context,
event WorkflowRegistryEvent,
) error {
if event.EventType != ForceUpdateSecretsEvent {
return fmt.Errorf("event type unsupported : %s", event.EventType)
}

url, err := getSecretsURL(event)
if err != nil {
h.lggr.Errorf("failed to get URL hash", err)
Expand All @@ -73,8 +82,15 @@ func (h *forceUpdateSecretsHandler) Handle(
return nil
}

// getSecretsURL returns the URL of the secrets contents from the event data and fails
// if the URL is not found or is not a string.
func getSecretsURL(event WorkflowRegistryEvent) (string, error) {
url, ok := event.Data["SecretsURL"].(string)
raw, found := event.Data["SecretsURL"]
if !found {
return "", fmt.Errorf("failed to fetch secrets hash from event : %+v", event.Data)
}

url, ok := raw.(string)
if !ok {
return "", fmt.Errorf("failed to fetch secrets hash from event : %+v", event.Data)
}
Expand Down
Loading

0 comments on commit 38ebd33

Please sign in to comment.