-
Notifications
You must be signed in to change notification settings - Fork 0
CROSSLINK-252 Add option to broadcast all event states #522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JanisSaldabols
wants to merge
1
commit into
main
Choose a base branch
from
CROSSLINK-252
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+40
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -35,8 +35,10 @@ type EventBus interface { | |
| CreateNoticeWithParent(id string, eventName EventName, data EventData, status EventStatus, eventDomain EventDomain, parentId *string) (string, error) | ||
| // Mark task for processing or fail if status is invalid (e.g already started) | ||
| BeginTask(eventId string) (Event, error) | ||
| BeginTaskBroadcast(eventId string) (Event, error) | ||
| // Mark task as completed or fail if status is invalid (e.g not started) | ||
| CompleteTask(eventId string, result *EventResult, status EventStatus) (Event, error) | ||
| CompleteTaskBroadcast(eventId string, result *EventResult, status EventStatus) (Event, error) | ||
| // Register handler for event (task or notice) created signal | ||
| HandleEventCreated(eventName EventName, f func(ctx common.ExtendedContext, event Event)) | ||
| // Register handler for task started signal | ||
|
|
@@ -45,6 +47,7 @@ type EventBus interface { | |
| HandleTaskCompleted(eventName EventName, f func(ctx common.ExtendedContext, event Event)) | ||
| // Execute task processing function within an automatic Begin/Complete block. | ||
| ProcessTask(ctx common.ExtendedContext, event Event, h func(common.ExtendedContext, Event) (EventStatus, *EventResult)) (Event, error) | ||
| ProcessTaskBroadcast(ctx common.ExtendedContext, event Event, h func(common.ExtendedContext, Event) (EventStatus, *EventResult)) (Event, error) | ||
| FindAncestor(descendant *Event, eventName EventName) *Event | ||
| GetLatestRequestEventByAction(ctx common.ExtendedContext, illTransId string, action string) (Event, error) | ||
| } | ||
|
|
@@ -270,6 +273,14 @@ func (p *PostgresEventBus) createNotice(classId string, eventName EventName, dat | |
| } | ||
|
|
||
| func (p *PostgresEventBus) BeginTask(eventId string) (Event, error) { | ||
| return p.beginTask(eventId, false) | ||
| } | ||
|
|
||
| func (p *PostgresEventBus) BeginTaskBroadcast(eventId string) (Event, error) { | ||
| return p.beginTask(eventId, true) | ||
| } | ||
|
|
||
| func (p *PostgresEventBus) beginTask(eventId string, broadcast bool) (Event, error) { | ||
| var event Event | ||
| err := p.repo.WithTxFunc(p.ctx, func(eventRepo EventRepo) error { | ||
| var err error | ||
|
|
@@ -283,10 +294,15 @@ func (p *PostgresEventBus) BeginTask(eventId string) (Event, error) { | |
| if event.EventStatus != EventStatusNew { | ||
| return fmt.Errorf("cannot begin task processing, event is not in state NEW but %s", event.EventStatus) | ||
| } | ||
| broadcastValue := event.Broadcast | ||
| if broadcast { | ||
| broadcastValue = broadcast | ||
| } | ||
| event, err = eventRepo.UpdateEventStatus(p.ctx, UpdateEventStatusParams{ | ||
| ID: eventId, | ||
| EventStatus: EventStatusProcessing, | ||
| LastSignal: string(SignalTaskBegin), | ||
| Broadcast: broadcastValue, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -298,6 +314,14 @@ func (p *PostgresEventBus) BeginTask(eventId string) (Event, error) { | |
| } | ||
|
|
||
| func (p *PostgresEventBus) CompleteTask(eventId string, result *EventResult, status EventStatus) (Event, error) { | ||
| return p.completeTask(eventId, result, status, false) | ||
| } | ||
|
|
||
| func (p *PostgresEventBus) CompleteTaskBroadcast(eventId string, result *EventResult, status EventStatus) (Event, error) { | ||
| return p.completeTask(eventId, result, status, true) | ||
| } | ||
|
|
||
| func (p *PostgresEventBus) completeTask(eventId string, result *EventResult, status EventStatus, broadcast bool) (Event, error) { | ||
| var event Event | ||
| err := p.repo.WithTxFunc(p.ctx, func(eventRepo EventRepo) error { | ||
| var err error | ||
|
|
@@ -316,6 +340,9 @@ func (p *PostgresEventBus) CompleteTask(eventId string, result *EventResult, sta | |
| event.ResultData = *result | ||
| } | ||
| event.LastSignal = string(SignalTaskComplete) | ||
| if broadcast { | ||
| event.Broadcast = broadcast | ||
| } | ||
| event, err = eventRepo.SaveEvent(p.ctx, SaveEventParams(event)) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -357,16 +384,24 @@ func (p *PostgresEventBus) HandleTaskCompleted(eventName EventName, f func(ctx c | |
| } | ||
|
|
||
| func (p *PostgresEventBus) ProcessTask(ctx common.ExtendedContext, event Event, h func(common.ExtendedContext, Event) (EventStatus, *EventResult)) (Event, error) { | ||
| return p.processTask(ctx, event, h, p.BeginTask, p.CompleteTask) | ||
| } | ||
|
|
||
| func (p *PostgresEventBus) ProcessTaskBroadcast(ctx common.ExtendedContext, event Event, h func(common.ExtendedContext, Event) (EventStatus, *EventResult)) (Event, error) { | ||
| return p.processTask(ctx, event, h, p.BeginTaskBroadcast, p.CompleteTaskBroadcast) | ||
|
|
||
| } | ||
|
Comment on lines
+390
to
+392
|
||
|
|
||
| func (p *PostgresEventBus) processTask(ctx common.ExtendedContext, event Event, h func(common.ExtendedContext, Event) (EventStatus, *EventResult), b func(eventId string) (Event, error), c func(eventId string, result *EventResult, status EventStatus) (Event, error)) (Event, error) { | ||
| inEvent := &event | ||
| event, err := p.BeginTask(event.ID) | ||
| event, err := b(event.ID) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we call these handlers something more readable like begin and complete? |
||
| if err != nil { | ||
| p.getEventContext(inEvent).Logger().Warn("failed to start processing TASK event", "error", err, "eventName", inEvent.EventName) | ||
| return event, err | ||
| } | ||
|
|
||
| status, result := h(ctx, event) | ||
|
|
||
| event, err = p.CompleteTask(event.ID, result, status) | ||
| event, err = c(event.ID, result, status) | ||
| if err != nil { | ||
| p.getEventContext(inEvent).Logger().Warn("failed to complete processing TASK event", "error", err, "eventName", inEvent.EventName) | ||
| return event, err | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -75,7 +75,7 @@ DELETE FROM event | |
| WHERE ill_transaction_id = $1; | ||
|
|
||
| -- name: UpdateEventStatus :one | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe rename this to something like UpdateEventLifecycle |
||
| UPDATE event SET last_signal = $3, event_status = $2 | ||
| UPDATE event SET last_signal = $3, event_status = $2, broadcast = $4 | ||
| WHERE id = $1 | ||
| RETURNING sqlc.embed(event); | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JanisSaldabols we need to test this somehow