-
Notifications
You must be signed in to change notification settings - Fork 170
Remove post-persist ambiguity and have events match emitted state #1350
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,51 @@ type CompleterJobUpdated struct { | |
| Reason riverdriver.JobSetStateReason | ||
| } | ||
|
|
||
| func newCompleterJobUpdated(job *rivertype.JobRow, stats *jobstats.JobStatistics, requestedReason riverdriver.JobSetStateReason) CompleterJobUpdated { | ||
|
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. I might opt to have this method be only focused on the state/reason since afaict that's all it's actually returning, but it's minor so up to you for sure! |
||
| var reason riverdriver.JobSetStateReason | ||
| switch job.State { | ||
| case rivertype.JobStateAvailable: | ||
| // Available is ambiguous: failed jobs being retried immediately, short | ||
| // snoozes, and jobs interrupted by client shutdown all use it. Preserve | ||
| // the requested reason when it describes one of those transitions. | ||
| switch requestedReason { | ||
| case riverdriver.JobSetStateReasonFailed, riverdriver.JobSetStateReasonInterrupted, riverdriver.JobSetStateReasonSnoozed: | ||
| reason = requestedReason | ||
| case riverdriver.JobSetStateReasonCancelled, riverdriver.JobSetStateReasonCompleted: | ||
| reason = riverdriver.JobSetStateReasonFailed | ||
| default: | ||
| panic("completion subscriber received an unknown reason, river bug") | ||
| } | ||
| case rivertype.JobStateCancelled: | ||
| reason = riverdriver.JobSetStateReasonCancelled | ||
|
|
||
| case rivertype.JobStateCompleted: | ||
| reason = riverdriver.JobSetStateReasonCompleted | ||
|
|
||
| case rivertype.JobStateDiscarded, rivertype.JobStateRetryable: | ||
| reason = riverdriver.JobSetStateReasonFailed | ||
|
|
||
| case rivertype.JobStateScheduled: | ||
| reason = riverdriver.JobSetStateReasonSnoozed | ||
|
|
||
| case rivertype.JobStatePending, rivertype.JobStateRunning: | ||
| // Neither state represents a finalized job, so emitting a completion | ||
| // event would be misleading. Reaching this case indicates a River bug or | ||
| // that the job's state was changed out of band during finalization. | ||
| panic("completion subscriber received a job that wasn't finalized, river bug") | ||
|
|
||
| default: | ||
| // linter exhaustive rule prevents this from being reached. | ||
| panic("completion subscriber received a job with an unknown state, river bug") | ||
| } | ||
|
|
||
| return CompleterJobUpdated{ | ||
| Job: job, | ||
| JobStats: stats, | ||
| Reason: reason, | ||
| } | ||
| } | ||
|
|
||
| type InlineCompleter struct { | ||
| baseservice.BaseService | ||
| startstop.BaseStartStop | ||
|
|
@@ -101,11 +146,7 @@ func (c *InlineCompleter) JobSetStateIfRunning(ctx context.Context, stats *jobst | |
| } | ||
|
|
||
| stats.CompleteDuration = c.Time.Now().Sub(start) | ||
| c.subscribeCh <- []CompleterJobUpdated{{ | ||
| Job: jobs[0], | ||
| JobStats: stats, | ||
| Reason: params.Reason, | ||
| }} | ||
| c.subscribeCh <- []CompleterJobUpdated{newCompleterJobUpdated(jobs[0], stats, params.Reason)} | ||
|
|
||
| return nil | ||
| } | ||
|
|
@@ -216,11 +257,7 @@ func (c *AsyncCompleter) JobSetStateIfRunning(ctx context.Context, stats *jobsta | |
| } | ||
|
|
||
| stats.CompleteDuration = c.Time.Now().Sub(start) | ||
| c.subscribeCh <- []CompleterJobUpdated{{ | ||
| Job: jobs[0], | ||
| JobStats: stats, | ||
| Reason: params.Reason, | ||
| }} | ||
| c.subscribeCh <- []CompleterJobUpdated{newCompleterJobUpdated(jobs[0], stats, params.Reason)} | ||
|
|
||
| return nil | ||
| }) | ||
|
|
@@ -508,11 +545,7 @@ func (c *BatchCompleter) handleBatch(ctx context.Context) error { | |
| for _, jobRow := range jobRows { | ||
| setState := setStateBatch[jobRow.ID] | ||
| setState.Stats.CompleteDuration = completeTime.Sub(setState.StartTime) | ||
| events = append(events, CompleterJobUpdated{ | ||
| Job: jobRow, | ||
| JobStats: setState.Stats, | ||
| Reason: setState.Params.Reason, | ||
| }) | ||
| events = append(events, newCompleterJobUpdated(jobRow, setState.Stats, setState.Params.Reason)) | ||
| } | ||
|
|
||
| if len(events) > 0 { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Do you think this deserves any further detail on how this might impact people whose programs are written against these states?