Repository navigation
Add sequences information to job detail page #739
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
brandur
wants to merge
3
commits into
master
Choose a base branch
from
sequence-diagnostics
base: master
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.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| .tool-versions | ||
| /riverui | ||
| /riverproui/riverproui | ||
| /go.work | ||
| /go.work.sum | ||
|
|
||
| # Logs | ||
| logs | ||
|
|
||
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
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
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 |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| package riveruidrivertest | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/riverqueue/river/riverdriver" | ||
| "github.com/riverqueue/river/rivershared/testfactory" | ||
| "github.com/riverqueue/river/rivershared/util/dbutil" | ||
| "github.com/riverqueue/river/rivertype" | ||
|
|
||
| "riverqueue.com/riverui/internal/riveruidriver" | ||
| ) | ||
|
|
||
| func exerciseJobSequenceGet(ctx context.Context, t *testing.T, driver riveruidriver.Driver, executorWithTx func(context.Context, *testing.T) (riverdriver.Executor, string)) { | ||
| t.Helper() | ||
|
|
||
| t.Run("JobSequenceGet", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| type testBundle struct { | ||
| exec riveruidriver.Executor | ||
| insert func(rivertype.JobState, string) *rivertype.JobRow | ||
| inspect func(int64) *riveruidriver.JobSequence | ||
| prefix string | ||
| } | ||
| setup := func(t *testing.T) *testBundle { | ||
| t.Helper() | ||
| exec, schema := executorWithSchema(ctx, t, driver, executorWithTx) | ||
| prefix := "" | ||
| if schema != "" { | ||
| prefix = dbutil.SafeIdentifier(schema) + "." | ||
| } | ||
| return &testBundle{ | ||
| exec: exec, | ||
| insert: func(state rivertype.JobState, metadata string) *rivertype.JobRow { | ||
| return testfactory.Job(ctx, t, exec, &testfactory.JobOpts{Metadata: []byte(metadata), Schema: schema, State: &state}) | ||
| }, | ||
| inspect: func(id int64) *riveruidriver.JobSequence { | ||
| result, err := exec.JobSequenceGet(ctx, &riveruidriver.JobSequenceGetParams{ID: id, Schema: schema}) | ||
| require.NoError(t, err) | ||
| return result | ||
| }, | ||
| prefix: prefix, | ||
| } | ||
| } | ||
|
|
||
| for _, state := range []rivertype.JobState{rivertype.JobStateAvailable, rivertype.JobStateCancelled, rivertype.JobStateDiscarded, rivertype.JobStateRetryable, rivertype.JobStateRunning, rivertype.JobStateScheduled} { | ||
| t.Run(string(state), func(t *testing.T) { | ||
| t.Parallel() | ||
| bundle := setup(t) | ||
| // Completed history and other keys must never become blockers. | ||
| bundle.insert(rivertype.JobStateCompleted, `{"seq_key":"invoice"}`) | ||
| bundle.insert(rivertype.JobStateCancelled, `{"seq_key":"other"}`) | ||
| blocker := bundle.insert(state, `{"seq_key":"invoice"}`) | ||
| first := bundle.insert(rivertype.JobStatePending, `{"seq_key":"invoice","seq_continue_cancelled":true,"seq_continue_discarded":true}`) | ||
| last := bundle.insert(rivertype.JobStatePending, `{"seq_key":"invoice"}`) | ||
| result := bundle.inspect(last.ID) | ||
| require.Equal(t, "invoice", result.Key) | ||
| require.Equal(t, last.ID, result.JobID) | ||
| require.Equal(t, first.ID, result.FirstPending.ID) | ||
| require.Len(t, result.Blockers, 1) | ||
| require.Equal(t, blocker.ID, result.Blockers[0].ID) | ||
| require.Equal(t, blocker.Kind, result.Blockers[0].Kind) | ||
| require.Equal(t, blocker.Queue, result.Blockers[0].Queue) | ||
| require.Equal(t, state, result.Blockers[0].State) | ||
| if state == rivertype.JobStateCancelled || state == rivertype.JobStateDiscarded { | ||
| require.Equal(t, "halted", result.WaitReason()) | ||
| } else { | ||
| require.Equal(t, "waiting", result.WaitReason()) | ||
| } | ||
| require.Equal(t, "none", bundle.inspect(blocker.ID).WaitReason()) | ||
| }) | ||
| } | ||
|
|
||
| t.Run("ActiveAfterPendingHead", func(t *testing.T) { | ||
| t.Parallel() | ||
| bundle := setup(t) | ||
| first := bundle.insert(rivertype.JobStatePending, `{"seq_key":"invoice"}`) | ||
| active := bundle.insert(rivertype.JobStateRunning, `{"seq_key":"invoice"}`) | ||
| result := bundle.inspect(first.ID) | ||
| require.Equal(t, "waiting", result.WaitReason()) | ||
| require.Len(t, result.Blockers, 1) | ||
| require.Equal(t, active.ID, result.Blockers[0].ID) | ||
| }) | ||
|
|
||
| t.Run("ContinuationAndTerminalPosition", func(t *testing.T) { | ||
| t.Parallel() | ||
| bundle := setup(t) | ||
| bundle.insert(rivertype.JobStateCancelled, `{"seq_key":"invoice","seq_continue_cancelled":true}`) | ||
| bundle.insert(rivertype.JobStateDiscarded, `{"seq_key":"invoice","seq_continue_discarded":true}`) | ||
| first := bundle.insert(rivertype.JobStatePending, `{"seq_key":"invoice"}`) | ||
| bundle.insert(rivertype.JobStateCancelled, `{"seq_key":"invoice"}`) | ||
| bundle.insert(rivertype.JobStateDiscarded, `{"seq_key":"invoice"}`) | ||
| last := bundle.insert(rivertype.JobStatePending, `{"seq_key":"invoice"}`) | ||
| result := bundle.inspect(first.ID) | ||
| require.Empty(t, result.Blockers) | ||
| require.Equal(t, "awaiting_promotion", result.WaitReason()) | ||
| require.Equal(t, "waiting", bundle.inspect(last.ID).WaitReason()) | ||
| }) | ||
|
|
||
| t.Run("EarliestBlockerPerState", func(t *testing.T) { | ||
| t.Parallel() | ||
| bundle := setup(t) | ||
| cancelled := bundle.insert(rivertype.JobStateCancelled, `{"seq_key":"invoice"}`) | ||
| bundle.insert(rivertype.JobStateCancelled, `{"seq_key":"invoice"}`) | ||
| discarded := bundle.insert(rivertype.JobStateDiscarded, `{"seq_key":"invoice"}`) | ||
| pending := bundle.insert(rivertype.JobStatePending, `{"seq_key":"invoice"}`) | ||
| result := bundle.inspect(pending.ID) | ||
| require.Len(t, result.Blockers, 2) | ||
| require.Equal(t, cancelled.ID, result.Blockers[0].ID) | ||
| require.Equal(t, discarded.ID, result.Blockers[1].ID) | ||
| }) | ||
|
|
||
| t.Run("MissingAndNonSequence", func(t *testing.T) { | ||
| t.Parallel() | ||
| bundle := setup(t) | ||
| require.Nil(t, bundle.inspect(9223372036854775807)) | ||
| for _, metadata := range []string{`{}`, `{"seq_key":null}`, `{"seq_key":123}`, `{"seq_key":""}`} { | ||
| job := bundle.insert(rivertype.JobStatePending, metadata) | ||
| require.Nil(t, bundle.inspect(job.ID)) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("Recovery", func(t *testing.T) { | ||
| t.Parallel() | ||
| bundle := setup(t) | ||
| blocker := bundle.insert(rivertype.JobStateDiscarded, `{"seq_key":"invoice"}`) | ||
| pending := bundle.insert(rivertype.JobStatePending, `{"seq_key":"invoice"}`) | ||
| require.Equal(t, "halted", bundle.inspect(pending.ID).WaitReason()) | ||
| require.NoError(t, bundle.exec.Exec(ctx, fmt.Sprintf("UPDATE %sriver_job SET state = 'pending', finalized_at = NULL WHERE id = %d", bundle.prefix, blocker.ID))) | ||
| result := bundle.inspect(pending.ID) | ||
| require.Equal(t, blocker.ID, result.FirstPending.ID) | ||
| require.Equal(t, "waiting", result.WaitReason()) | ||
| require.NoError(t, bundle.exec.Exec(ctx, fmt.Sprintf("DELETE FROM %sriver_job WHERE id = %d", bundle.prefix, blocker.ID))) | ||
| require.Equal(t, "awaiting_promotion", bundle.inspect(pending.ID).WaitReason()) | ||
| }) | ||
| }) | ||
| } |
2 changes: 2 additions & 0 deletions
2
internal/riveruidriver/riveruipostgres/internal/dbsqlc/models.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
105 changes: 105 additions & 0 deletions
105
internal/riveruidriver/riveruipostgres/internal/dbsqlc/sequence.sql
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 |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| -- Each probe constrains state and sequence key before ordering by ID. This | ||
| -- matches River Pro's river_job_sequence_scheduling index and excludes completed | ||
| -- history. Separate active-state probes avoid sorting an entire sequence. | ||
| -- Terminal blockers must precede the first pending job and use their own | ||
| -- continuation flags, matching the sequence supervisor. Active jobs block from | ||
| -- anywhere in the sequence, including after its pending head. | ||
| -- name: JobSequenceGet :one | ||
| WITH target AS ( | ||
| SELECT job.id, job.state, job.metadata->>'seq_key' AS seq_key | ||
| FROM /* TEMPLATE: schema */river_job AS job | ||
| WHERE job.id = @job_id::bigint | ||
| AND job.metadata ? 'seq_key' | ||
| AND jsonb_typeof(job.metadata->'seq_key') = 'string' | ||
| AND job.metadata->>'seq_key' <> '' | ||
| ), | ||
| first_pending AS ( | ||
| SELECT job.id, job.kind, job.queue, job.state, job.scheduled_at | ||
| FROM /* TEMPLATE: schema */river_job AS job | ||
| WHERE job.state = 'pending' | ||
| AND job.metadata ? 'seq_key' | ||
| AND job.metadata->>'seq_key' = (SELECT seq_key FROM target) | ||
| ORDER BY job.id | ||
| LIMIT 1 | ||
| ), | ||
| available_blocker AS ( | ||
| SELECT job.id, job.kind, job.queue, job.state, job.scheduled_at | ||
| FROM /* TEMPLATE: schema */river_job AS job | ||
| WHERE job.state = 'available' | ||
| AND job.metadata ? 'seq_key' | ||
| AND job.metadata->>'seq_key' = (SELECT seq_key FROM target) | ||
| ORDER BY job.id | ||
| LIMIT 1 | ||
| ), | ||
| cancelled_blocker AS ( | ||
| SELECT job.id, job.kind, job.queue, job.state, job.scheduled_at | ||
| FROM /* TEMPLATE: schema */river_job AS job | ||
| WHERE job.state = 'cancelled' | ||
| AND job.metadata ? 'seq_key' | ||
| AND job.metadata->>'seq_key' = (SELECT seq_key FROM target) | ||
| AND job.id < (SELECT first_pending.id FROM first_pending) | ||
| AND NOT COALESCE((job.metadata->'seq_continue_cancelled')::boolean, false) | ||
| ORDER BY job.id | ||
| LIMIT 1 | ||
| ), | ||
| discarded_blocker AS ( | ||
| SELECT job.id, job.kind, job.queue, job.state, job.scheduled_at | ||
| FROM /* TEMPLATE: schema */river_job AS job | ||
| WHERE job.state = 'discarded' | ||
| AND job.metadata ? 'seq_key' | ||
| AND job.metadata->>'seq_key' = (SELECT seq_key FROM target) | ||
| AND job.id < (SELECT first_pending.id FROM first_pending) | ||
| AND NOT COALESCE((job.metadata->'seq_continue_discarded')::boolean, false) | ||
| ORDER BY job.id | ||
| LIMIT 1 | ||
| ), | ||
| retryable_blocker AS ( | ||
| SELECT job.id, job.kind, job.queue, job.state, job.scheduled_at | ||
| FROM /* TEMPLATE: schema */river_job AS job | ||
| WHERE job.state = 'retryable' | ||
| AND job.metadata ? 'seq_key' | ||
| AND job.metadata->>'seq_key' = (SELECT seq_key FROM target) | ||
| ORDER BY job.id | ||
| LIMIT 1 | ||
| ), | ||
| running_blocker AS ( | ||
| SELECT job.id, job.kind, job.queue, job.state, job.scheduled_at | ||
| FROM /* TEMPLATE: schema */river_job AS job | ||
| WHERE job.state = 'running' | ||
| AND job.metadata ? 'seq_key' | ||
| AND job.metadata->>'seq_key' = (SELECT seq_key FROM target) | ||
| ORDER BY job.id | ||
| LIMIT 1 | ||
| ), | ||
| scheduled_blocker AS ( | ||
| SELECT job.id, job.kind, job.queue, job.state, job.scheduled_at | ||
| FROM /* TEMPLATE: schema */river_job AS job | ||
| WHERE job.state = 'scheduled' | ||
| AND job.metadata ? 'seq_key' | ||
| AND job.metadata->>'seq_key' = (SELECT seq_key FROM target) | ||
| ORDER BY job.id | ||
| LIMIT 1 | ||
| ), | ||
| blockers AS ( | ||
| SELECT * FROM available_blocker | ||
| UNION ALL | ||
| SELECT * FROM cancelled_blocker | ||
| UNION ALL | ||
| SELECT * FROM discarded_blocker | ||
| UNION ALL | ||
| SELECT * FROM retryable_blocker | ||
| UNION ALL | ||
| SELECT * FROM running_blocker | ||
| UNION ALL | ||
| SELECT * FROM scheduled_blocker | ||
| ) | ||
| SELECT COALESCE(( | ||
| SELECT json_build_object( | ||
| 'job_id', target.id, | ||
| 'job_state', target.state, | ||
| 'key', target.seq_key, | ||
| 'first_pending', (SELECT row_to_json(first_pending) FROM first_pending), | ||
| 'blockers', COALESCE((SELECT json_agg(blockers ORDER BY id) FROM blockers), '[]'::json) | ||
| )::text | ||
| FROM target | ||
| ), 'null')::text AS sequence; |
Oops, something went wrong.
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.
Codex keeps finding workarounds like this one to CI passing properly when API changes between UI and Pro UI. This seems to work okay and gets CI to pass, so left it.