Skip to content

Commit

Permalink
UML-3724 updated terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
allenannom committed Jan 16, 2025
1 parent 1632bf1 commit 941f6fd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 44 deletions.
41 changes: 18 additions & 23 deletions lambda-functions/event-receiver/app/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,34 @@ import (
"github.com/aws/aws-lambda-go/events"
)

type CloudWatchHandler interface {
Handle(ctx context.Context, event events.CloudWatchEvent) error
type SQSEventHandler interface {
Handle(ctx context.Context, event events.SQSEvent) error
}

type cloudWatchHandler struct {
type sqsEventHandler struct {
factory Factory
logger Logger
}

func NewCloudWatchHandler(factory Factory, logger Logger) CloudWatchHandler {
return &cloudWatchHandler{
func NewSQSEventHandler(factory Factory, logger Logger) SQSEventHandler {
return &sqsEventHandler{
factory: factory,
logger: logger,
}
}

func (h *cloudWatchHandler) Handle(ctx context.Context, event events.CloudWatchEvent) error {
var parsedEvent events.CloudWatchEvent

h.logger.Info("Received CloudWatch event", "source", event.Source)

err := json.Unmarshal(event.Detail, &parsedEvent)
if err != nil {
h.logger.Error("Failed to unmarshal event detail", err)
return fmt.Errorf("failed to unmarshal event: %w", err)
}

switch parsedEvent.Source {
case "opg.poas.makeregister":
h.logger.Info("Handling 'makeregister' event", "detailType", parsedEvent.DetailType)
default:
h.logger.Warn("Unhandled event source: " + parsedEvent.Source, err)
}

func (h *sqsEventHandler) Handle(ctx context.Context, event events.SQSEvent) error {
for _, record := range event.Records {
h.logger.Info("Received SQS event")

var payload map[string]interface{}
err := json.Unmarshal([]byte(record.Body), &payload)
if err != nil {
h.logger.Error("Failed to unmarshal event detail", err)
return fmt.Errorf("failed to unmarshal event: %w", err)
}
h.logger.Info("Processed SQS Event' event", "payload", payload)
}
return nil

}
12 changes: 0 additions & 12 deletions lambda-functions/event-receiver/app/handler_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion lambda-functions/event-receiver/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {

appFactory := NewFactory(cfg, logger)

handler := NewCloudWatchHandler(appFactory, logger)
handler := NewSQSEventHandler(appFactory, logger)

lambda.Start(handler)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 941f6fd

Please sign in to comment.