Skip to content

Commit

Permalink
chore(workflows): stub out event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
MStreet3 committed Nov 21, 2024
1 parent 64aeef9 commit 4f88ad1
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 16 deletions.
118 changes: 118 additions & 0 deletions core/services/workflows/syncer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,88 @@ package syncer
import (
"context"
"encoding/hex"
"errors"
"fmt"

"github.com/smartcontractkit/chainlink/v2/core/logger"
)

var ErrNotImplemented = errors.New("not implemented")

// WorkflowRegistryrEventType is the type of event that is emitted by the WorkflowRegistry
type WorkflowRegistryEventType string

var (
// ForceUpdateSecretsEvent is emitted when a request to force update a workflows secrets is made
ForceUpdateSecretsEvent WorkflowRegistryEventType = "WorkflowForceUpdateSecretsRequestedV1"

// WorkflowRegisteredEvent is emitted when a workflow is registered
WorkflowRegisteredEvent WorkflowRegistryEventType = "WorkflowRegisteredV1"

// WorkflowUpdatedEvent is emitted when a workflow is updated
WorkflowUpdatedEvent WorkflowRegistryEventType = "WorkflowUpdatedV1"

// WorkflowPausedEvent is emitted when a workflow is paused
WorkflowPausedEvent WorkflowRegistryEventType = "WorkflowPausedV1"

// WorkflowActivatedEvent is emitted when a workflow is activated
WorkflowActivatedEvent WorkflowRegistryEventType = "WorkflowActivatedV1"

// WorkflowDeletedEvent is emitted when a workflow is deleted
WorkflowDeletedEvent WorkflowRegistryEventType = "WorkflowDeletedV1"
)

// WorkflowRegistryForceUpdateSecretsRequestedV1 is a chain agnostic definition of the WorkflowRegistry
// ForceUpdateSecretsRequested event.
type WorkflowRegistryForceUpdateSecretsRequestedV1 struct {
SecretsURLHash []byte
Owner []byte
WorkflowName string
}

type WorkflowRegistryWorkflowRegisteredV1 struct {
WorkflowID [32]byte
WorkflowOwner []byte
DonID uint32
Status uint8
WorkflowName string
BinaryURL string
ConfigURL string
SecretsURL string
}

type WorkflowRegistryWorkflowUpdatedV1 struct {
OldWorkflowID [32]byte
WorkflowOwner []byte
DonID uint32
NewWorkflowID [32]byte
WorkflowName string
BinaryURL string
ConfigURL string
SecretsURL string
}

type WorkflowRegistryWorkflowPausedV1 struct {
WorkflowID [32]byte
WorkflowOwner []byte
DonID uint32
WorkflowName string
}

type WorkflowRegistryWorkflowActivatedV1 struct {
WorkflowID [32]byte
WorkflowOwner []byte
DonID uint32
WorkflowName string
}

type WorkflowRegistryWorkflowDeletedV1 struct {
WorkflowID [32]byte
WorkflowOwner []byte
DonID uint32
WorkflowName string
}

// eventHandler is a handler for WorkflowRegistryEvent events. Each event type has a corresponding
// method that handles the event.
type eventHandler struct {
Expand All @@ -33,11 +110,52 @@ func (h *eventHandler) Handle(ctx context.Context, event WorkflowRegistryEvent)
switch event.EventType {
case ForceUpdateSecretsEvent:
return h.forceUpdateSecretsEvent(ctx, event)
case WorkflowRegisteredEvent:
return h.workflowRegisteredEvent(ctx, event)
case WorkflowUpdatedEvent:
return h.workflowUpdatedEvent(ctx, event)
case WorkflowPausedEvent:
return h.workflowPausedEvent(ctx, event)
case WorkflowActivatedEvent:
return h.workflowActivatedEvent(ctx, event)
default:
return fmt.Errorf("event type unsupported: %v", event.EventType)
}
}

// workflowRegisteredEvent handles the WorkflowRegisteredEvent event type.
// TODO: Implement this method
func (h *eventHandler) workflowRegisteredEvent(
_ context.Context,
_ WorkflowRegistryEvent,
) error {
return ErrNotImplemented
}

// workflowUpdatedEvent handles the WorkflowUpdatedEvent event type.
func (h *eventHandler) workflowUpdatedEvent(
_ context.Context,
_ WorkflowRegistryEvent,
) error {
return ErrNotImplemented
}

// workflowPausedEvent handles the WorkflowPausedEvent event type.
func (h *eventHandler) workflowPausedEvent(
_ context.Context,
_ WorkflowRegistryEvent,
) error {
return ErrNotImplemented
}

// workflowActivatedEvent handles the WorkflowActivatedEvent event type.
func (h *eventHandler) workflowActivatedEvent(
_ context.Context,
_ WorkflowRegistryEvent,
) error {
return ErrNotImplemented
}

// forceUpdateSecretsEvent handles the ForceUpdateSecretsEvent event type.
func (h *eventHandler) forceUpdateSecretsEvent(
ctx context.Context,
Expand Down
16 changes: 0 additions & 16 deletions core/services/workflows/syncer/workflow_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ var (
ContractName = "WorkflowRegistry"
)

// WorkflowRegistryrEventType is the type of event that is emitted by the WorkflowRegistry
type WorkflowRegistryEventType string

var (
// ForceUpdateSecretsEvent is emitted when a request to force update a workflows secrets is made
ForceUpdateSecretsEvent WorkflowRegistryEventType = "WorkflowForceUpdateSecretsRequestedV1"
)

// WorkflowRegistryForceUpdateSecretsRequestedV1 is a chain agnostic definition of the WorkflowRegistry
// ForceUpdateSecretsRequested event.
type WorkflowRegistryForceUpdateSecretsRequestedV1 struct {
SecretsURLHash []byte
Owner []byte
WorkflowName string
}

type Head struct {
Hash string
Height string
Expand Down

0 comments on commit 4f88ad1

Please sign in to comment.