-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Day 88/100 commits - add event handler for IaC Apply scheduled
- Loading branch information
1 parent
14abd80
commit e4714e2
Showing
6 changed files
with
65 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package handlers | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"golang.org/x/net/context" | ||
eb "labraboard/internal/eventbus" | ||
"labraboard/internal/eventbus/events" | ||
"labraboard/internal/logger" | ||
"labraboard/internal/repositories" | ||
) | ||
|
||
type scheduledIaCApplyHandler struct { | ||
eventSubscriber eb.EventSubscriber | ||
unitOfWork *repositories.UnitOfWork | ||
} | ||
|
||
func newScheduledIaCApplyHandler(eventSubscriber eb.EventSubscriber, unitOfWork *repositories.UnitOfWork) (*scheduledIaCApplyHandler, error) { | ||
return &scheduledIaCApplyHandler{ | ||
eventSubscriber, | ||
unitOfWork, | ||
}, nil | ||
} | ||
|
||
func (handler *scheduledIaCApplyHandler) Handle(ctx context.Context) { | ||
log := logger.GetWitContext(ctx).With().Str("event", string(events.IAC_APPLY_SCHEDULED)).Logger() | ||
locks := handler.eventSubscriber.Subscribe(events.SCHEDULED_PLAN, log.WithContext(ctx)) | ||
for msg := range locks { | ||
var event = events.IacApplyScheduled{} | ||
err := json.Unmarshal(msg, &event) | ||
if err != nil { | ||
log.Error().Err(fmt.Errorf("cannot handle message type %T", event)) | ||
} | ||
log.Info().Msgf("Received message: %s", msg) | ||
go handler.handle(event, log.WithContext(ctx)) | ||
} | ||
} | ||
|
||
func (handler *scheduledIaCApplyHandler) handle(event events.IacApplyScheduled, ctx context.Context) { | ||
log := logger.GetWitContext(ctx). | ||
With(). | ||
Str("changeId", event.ChangeId.String()). | ||
Str("iacType", string(event.IacType)). | ||
Str("planId", event.PlanId.String()). | ||
Str("projectId", event.ProjectId.String()). | ||
Str("owner", event.Owner). | ||
Logger() | ||
_, err := handler.unitOfWork.IacPlan.Get(event.PlanId, log.WithContext(ctx)) | ||
if err != nil { | ||
log.Error().Err(err) | ||
return | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters