repo_name stringlengths 1 62 | dataset stringclasses 1
value | lang stringclasses 11
values | pr_id int64 1 20.1k | owner stringlengths 2 34 | reviewer stringlengths 2 39 | diff_hunk stringlengths 15 262k | code_review_comment stringlengths 1 99.6k |
|---|---|---|---|---|---|---|---|
river | github_2023 | others | 456 | riverqueue | bgentry | @@ -15,4 +15,35 @@ INSERT INTO river_migration
SELECT created_at, 'main', version
FROM river_migration_old;
-DROP TABLE river_migration_old;
\ No newline at end of file
+DROP TABLE river_migration_old;
+
+--
+-- Create `river_client` and derivative.
+--
+-- This feature hasn't quite yet been implemented, but we're ... | notably this creates a hard constraint on unique client names, which may be breaking when rolled out |
river | github_2023 | go | 458 | riverqueue | bgentry | @@ -359,17 +359,33 @@ func migrateDown(ctx context.Context, logger *slog.Logger, out io.Writer, opts *
return true, nil
}
+// Rounds a duration so that it doesn't show so much cluttered and not useful
+// precision in printf output.
+func roundDuration(duration time.Duration) time.Duration {
+ switch {
+ case dura... | hah, thanks, I noticed this the other day and I'm glad you did too took the initiative to fix it! |
river | github_2023 | others | 443 | riverqueue | bgentry | @@ -1,6 +1,22 @@
-DROP INDEX river_migration_line_version_idx;
-CREATE UNIQUE INDEX river_migration_version_idx ON river_migration USING btree(version);
+--
+-- If any non-main migration are present, 005 should be considered irreversible.
+-- | Any way we could make this intentionally error? Thinking of something like selecting from a nonexistent column `irreversible_migration` if any values are in the set of `SELECT FROM river_migration WHERE line != 'main'` or something |
river | github_2023 | others | 443 | riverqueue | bgentry | @@ -1,12 +1,18 @@
ALTER TABLE river_migration
- ADD COLUMN line text;
+ RENAME TO river_migration_old;
-UPDATE river_migration
-SET line = 'main';
+CREATE TABLE river_migration(
+ created_at timestamptz NOT NULL DEFAULT NOW(),
+ line TEXT NOT NULL,
+ version bigint NOT NULL, | imo it's a little funky to not put the PK fields first just to make the default `SELECT * FROM river_migration` a bit cleaner. Seems like a warranted variance from the typical desire to alphabetize. |
river | github_2023 | go | 447 | riverqueue | bgentry | @@ -151,6 +151,13 @@ See the [`InsertAndWork` example] for complete code.
- [Work functions] for simplified worker implementation.
+## Cross language enqueueing
+
+River supports inserting jobs in some non-Go languages which are then be worked by Go implementations. This may be desirable in performance sensitive... | ```suggestion
River supports inserting jobs in some non-Go languages which are then worked by Go implementations. This may be desirable in performance sensitive cases so that jobs can take advantage of Go's fast runtime.
``` |
river | github_2023 | go | 438 | riverqueue | bgentry | @@ -427,14 +428,16 @@ func (s *PeriodicJobEnqueuer) insertParamsFromConstructor(ctx context.Context, c
return insertParams, uniqueOpts, true
}
+const periodicJobEnqueurVeryLongDuration = 24 * time.Hour | Small typo in the name of this long constant:
```suggestion
const periodicJobEnqueuerVeryLongDuration = 24 * time.Hour
``` |
river | github_2023 | go | 435 | riverqueue | bgentry | @@ -324,9 +325,21 @@ func (m *Migrator[TTx]) migrateDown(ctx context.Context, exec riverdriver.Execut
return res, nil
}
- if !opts.DryRun {
- if _, err := exec.MigrationDeleteByVersionMany(ctx, sliceutil.Map(res.Versions, migrateVersionToInt)); err != nil {
- return nil, fmt.Errorf("error deleting migration r... | The value 5 here might be clearer if put in a named constant |
river | github_2023 | go | 430 | riverqueue | bgentry | @@ -0,0 +1,25 @@
+package river
+
+import (
+ "github.com/riverqueue/river/rivershared/baseservice"
+ "github.com/riverqueue/river/rivershared/startstop"
+)
+
+// A plugin API that drivers may implemented to extend a River client. Driver | ```suggestion
// A plugin API that drivers may implement to extend a River client. Driver
``` |
river | github_2023 | go | 430 | riverqueue | bgentry | @@ -0,0 +1,99 @@
+package river
+
+import (
+ "context"
+ "testing"
+
+ "github.com/jackc/pgx/v5"
+ "github.com/jackc/pgx/v5/pgxpool"
+ "github.com/stretchr/testify/require"
+
+ "github.com/riverqueue/river/internal/riverinternaltest"
+ "github.com/riverqueue/river/riverdriver/riverpgxv5"
+ "github.com/riverqueue/river... | Might be helpful to have the test driver panic or `t.Fatal()` if it hasn't been init'd yet when these service methods are called. |
river | github_2023 | go | 432 | riverqueue | bgentry | @@ -164,7 +164,7 @@ func DrainContinuously[T any](drainChan <-chan T) func() []T {
func TestDB(ctx context.Context, tb testing.TB) *pgxpool.Pool {
tb.Helper()
- ctx, cancel := context.WithTimeout(ctx, 5*time.Second) | It's so weird that this is not long enough. Are we creating enough test DBs for the `GOMAXPROCS`? They really shouldn't be waiting at all if so, at least not longer than whatever the time is to close the pool and wait for `TruncateRiverTables` 🤔 |
river | github_2023 | go | 429 | riverqueue | bgentry | @@ -0,0 +1,183 @@
+package riversharedtest
+
+import (
+ "fmt"
+ "log/slog"
+ "os"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/require"
+ "go.uber.org/goleak"
+
+ "github.com/riverqueue/river/rivershared/baseservice"
+ "github.com/riverqueue/river/rivershared/slogtest"
+ "github.com/riverqueue/river/... | ```suggestion
// package and `WaitOrTimeout` above. Its main purpose is to allow a little
``` |
river | github_2023 | go | 410 | riverqueue | bgentry | @@ -1647,6 +1644,10 @@ func (c *Client[TTx]) JobListTx(ctx context.Context, tx TTx, params *JobListPara
// client, and can be used to add new ones or remove existing ones.
func (c *Client[TTx]) PeriodicJobs() *PeriodicJobBundle { return c.periodicJobs }
+// Queues returns the currently configured set of queues for ... | I don't think we want to have an exported method that returns an unexported type like this. Whether or not it works, it looks bad/undiscoverable in docs.
I think the type either needs to be exported with minimal methods exposed on it, or else we need to return an exported interface type here. |
river | github_2023 | go | 410 | riverqueue | bgentry | @@ -57,6 +57,8 @@ func (m *clientMonitor) Start(ctx context.Context) error {
// uninitialized. Unlike SetProducerStatus, it does not broadcast the change
// and is only meant to be used during initial client startup.
func (m *clientMonitor) InitializeProducerStatus(queueName string) {
+ m.statusSnapshotMu.Lock()
+ ... | Makes sense. As this wasn't dynamic before it wasn't really needed. |
river | github_2023 | go | 351 | riverqueue | bgentry | @@ -1264,6 +1268,18 @@ func insertParamsFromArgsAndOptions(args JobArgs, insertOpts *InsertOpts) (*rive
}
if tags == nil {
tags = []string{}
+ } else {
+ for _, tag := range tags {
+ if len(tag) > 255 {
+ return nil, nil, errors.New("tags should be a maximum of 255 characters long")
+ }
+ // Restricted... | maybe tags should be restricted to `/a-z_\-/i`? _possibly_ include single spaces in that but I don't think it would harm any use cases to leave that out. |
river | github_2023 | others | 351 | riverqueue | bgentry | @@ -22,10 +24,19 @@ sql:
emit_result_struct_pointers: true
rename:
- river_job_state: "JobState"
ttl: "TTL"
overrides:
+ # `database/sql` really does not play nicely with json/jsonb. If it's
+ # left as `[]byte` or `json.RawMessage`, `database/sql` wi... | ```suggestion
# but Postgres will also accept them as json/jsonb.
``` |
river | github_2023 | go | 351 | riverqueue | bgentry | @@ -1264,6 +1268,15 @@ func insertParamsFromArgsAndOptions(args JobArgs, insertOpts *InsertOpts) (*rive
}
if tags == nil {
tags = []string{}
+ } else {
+ for _, tag := range tags {
+ if len(tag) > 255 {
+ return nil, nil, errors.New("tags should be a maximum of 255 characters long")
+ }
+ if !tagRE.Mat... | This probably requires its own changelog entry. |
river | github_2023 | go | 351 | riverqueue | bgentry | @@ -70,107 +73,392 @@ func (e *Executor) Exec(ctx context.Context, sql string) (struct{}, error) {
}
func (e *Executor) JobCancel(ctx context.Context, params *riverdriver.JobCancelParams) (*rivertype.JobRow, error) {
- return nil, riverdriver.ErrNotImplemented
+ cancelledAt, err := params.CancelAttemptedAt.MarshalJ... | 😵💫 |
river | github_2023 | others | 423 | riverqueue | bgentry | @@ -11,6 +11,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Config.TestOnly` has been added. It disables various features in the River client like staggered maintenance service start that are useful in production, but may be somewhat harmful in tests because they make start... | Wrong version number? |
river | github_2023 | go | 423 | riverqueue | bgentry | @@ -234,7 +234,7 @@ func (e *jobExecutor) invokeErrorHandler(ctx context.Context, res *jobExecutorRe
case res.PanicVal != nil:
errorHandlerRes = invokeAndHandlePanic("HandlePanic", func() *ErrorHandlerResult {
- return e.ErrorHandler.HandlePanic(ctx, e.JobRow, res.PanicVal)
+ return e.ErrorHandler.HandlePani... | Should we convert this to string once when saving it to the result so that it doesn’t have to be cast here and by pgx when writing to the db? |
river | github_2023 | go | 399 | riverqueue | bgentry | @@ -616,6 +618,36 @@ func NewClient[TTx any](driver riverdriver.Driver[TTx], config *Config) (*Client
return client, nil
}
+func (c *Client[TTx]) AddQueue(queueName string, queueConfig QueueConfig) {
+ c.producersByQueueNameMu.Lock()
+ defer c.producersByQueueNameMu.Unlock()
+ c.producersByQueueName[queueName] = n... | This method is going to need to do some validation on the `QueueConfig` as [we currently do when initializing the client](https://github.com/riverqueue/river/blob/220a636820f37b9a7b16309d2863ef94124dc3db/client.go#L260-L267), and it will also need to return an `error` if validation fails.
We should probably extract ... |
river | github_2023 | go | 399 | riverqueue | bgentry | @@ -616,6 +618,36 @@ func NewClient[TTx any](driver riverdriver.Driver[TTx], config *Config) (*Client
return client, nil
}
+func (c *Client[TTx]) AddQueue(queueName string, queueConfig QueueConfig) {
+ c.producersByQueueNameMu.Lock()
+ defer c.producersByQueueNameMu.Unlock()
+ c.producersByQueueName[queueName] = n... | Should this one also return an `error`? We could reuse `rivertype.ErrNotFound` in case the queue does not exist. |
river | github_2023 | go | 399 | riverqueue | bgentry | @@ -616,6 +618,36 @@ func NewClient[TTx any](driver riverdriver.Driver[TTx], config *Config) (*Client
return client, nil
}
+func (c *Client[TTx]) AddQueue(queueName string, queueConfig QueueConfig) {
+ c.producersByQueueNameMu.Lock()
+ defer c.producersByQueueNameMu.Unlock()
+ c.producersByQueueName[queueName] = n... | Safe removal is a bit trickier than this. We need to actually shut down the producer somehow, and then the producer itself should be responsible for reporting its status to the monitor until it is shut down. At that point, yeah, we need to somehow remove it from the monitor's map so we don't keep old state around in th... |
river | github_2023 | go | 399 | riverqueue | bgentry | @@ -67,6 +67,13 @@ func (m *clientMonitor) SetProducerStatus(queueName string, status componentstat
m.bufferStatusUpdate()
}
+func (m *clientMonitor) RemoveProducerStatus(queueName string) {
+ m.statusSnapshotMu.Lock()
+ defer m.statusSnapshotMu.Unlock()
+ delete(m.currentSnapshot.Producers, queueName)
+ m.bufferS... | I think we can probably merge this into `SetProducer` and decide whether or not to remove based upon the status. |
river | github_2023 | go | 399 | riverqueue | brandur | @@ -616,6 +618,36 @@ func NewClient[TTx any](driver riverdriver.Driver[TTx], config *Config) (*Client
return client, nil
}
+func (c *Client[TTx]) AddQueue(queueName string, queueConfig QueueConfig) {
+ c.producersByQueueNameMu.Lock()
+ defer c.producersByQueueNameMu.Unlock()
+ c.producersByQueueName[queueName] = n... | Just given this is a lot of duplicative code, let's move this to a new `addProducer(queueName string, queueConfig QueueConfig)` internal helper that can share it with `Start`. |
river | github_2023 | go | 415 | riverqueue | bgentry | @@ -718,23 +718,36 @@ func (c *Client[TTx]) Start(ctx context.Context) error {
producer := producer
if err := producer.StartWorkContext(fetchCtx, workCtx); err != nil {
- stopProducers()
+ startstop.StopAllParallel(producersAsServices())
stopServicesOnError()
return err
}
}
return ... | At first I thought there was a typo, but maybe it's just worded awkwardly. This feels a bit clearer imo, up to you:
```suggestion
// Stop also cancels the "started" channel, so in case of a context
``` |
river | github_2023 | go | 415 | riverqueue | bgentry | @@ -97,19 +103,37 @@ type BaseStartStop struct {
// }
//
// ...
-func (s *BaseStartStop) StartInit(ctx context.Context) (context.Context, bool, chan struct{}) {
+func (s *BaseStartStop) StartInit(ctx context.Context) (context.Context, bool, func(), func()) { | This is where I start disliking the lint rule discouraging named return values. I mainly just want to see a label on things when there are this many, especially when there are consecutive values of the same type. |
river | github_2023 | others | 408 | riverqueue | bgentry | @@ -48,16 +48,14 @@ LIMIT @limit_count::integer;
-- name: QueuePause :execresult
WITH queue_to_update AS (
- SELECT name
+ SELECT name, paused_at
FROM river_queue
WHERE CASE WHEN @name::text = '*' THEN true ELSE river_queue.name = @name::text END
- AND paused_at IS NULL
FOR UPDATE
)
-
UP... | To avoid editing a row for no reason, we could take an approach we've done in some other queries: do the update in a CTE, and then for the final return do a union w/ the updated row and original row to return only one of them.
Not a high throughput query so it doesn't matter much, but it would be a nice tweak to sta... |
river | github_2023 | go | 403 | riverqueue | brandur | @@ -375,14 +375,14 @@ func (e *Elector) attemptResignLoop(ctx context.Context) {
// This does not inherit the parent context because we want to give up leadership
// even during a shutdown. There is no way to short-circuit this. | Maybe tweak this comment a little? |
river | github_2023 | go | 395 | riverqueue | bgentry | @@ -1112,7 +1119,7 @@ func (c *Client[TTx]) ID() string {
return c.config.ID
}
-func insertParamsFromConfigArgsAndOptions(config *Config, args JobArgs, insertOpts *InsertOpts) (*riverdriver.JobInsertFastParams, *dbunique.UniqueOpts, error) {
+func insertParamsFromConfigArgsAndOptions(archetype *baseservice.Archety... | Now that we're passing in a couple of fields from `Client` to this (neither of which was needed 1mo ago), it might be cleaner and less confusing to make it a method on `Client` instead. Borderline 🤷♂️ |
river | github_2023 | go | 390 | riverqueue | brandur | @@ -99,6 +99,20 @@ func (e *Executor) JobCountByState(ctx context.Context, state rivertype.JobState
return int(numJobs), nil
}
+func (e *Executor) JobDelete(ctx context.Context, id int64) (bool, error) {
+ job, err := e.queries.JobDelete(ctx, e.dbtx, id)
+ if err != nil {
+ return false, interpretError(err)
+ }
+... | Doesn't sqlc always return a not found error for a `:one` query rather than return a `nil`?
What do you think about adding a driver test case that verifies that a `JobDelete` on a non-existent row just to make sure the right thing happens here? |
river | github_2023 | go | 390 | riverqueue | brandur | @@ -1047,6 +1047,22 @@ func (c *Client[TTx]) jobCancel(ctx context.Context, exec riverdriver.Executor,
})
}
+// JobDelete deletes the job with the given ID from the database, returning
+// whether or not the job was deleted along with a possible error. Jobs in the
+// running state are not deleted.
+func (c *Clien... | Thoughts on returning the deleted job row instead of a bool? Feels like it gives you gives you more information and not a lot of downside. |
river | github_2023 | go | 390 | riverqueue | brandur | @@ -13,6 +13,10 @@ import (
// return this error.
var ErrNotFound = errors.New("not found")
+// ErrJobRunning is returned when a job is attempted to be deleted while it's
+// running.
+var ErrJobRunning = errors.New("job is running") | What do you think about a slightly more descriptive error message here in case this error bubbles up to an end user somewhere? Something like:
```suggestion
var ErrJobRunning = errors.New("running jobs cannot be deleted")
``` |
river | github_2023 | go | 379 | riverqueue | brandur | @@ -0,0 +1,271 @@
+package river
+
+import (
+ "context"
+ "fmt"
+ "sync"
+ "time"
+
+ "github.com/riverqueue/river/internal/baseservice"
+ "github.com/riverqueue/river/internal/jobcompleter"
+ "github.com/riverqueue/river/internal/jobstats"
+ "github.com/riverqueue/river/internal/util/sliceutil"
+ "github.com/riverque... | I'm having a hard time understanding this TODO — can we fix it? |
river | github_2023 | go | 379 | riverqueue | brandur | @@ -0,0 +1,271 @@
+package river
+
+import (
+ "context"
+ "fmt"
+ "sync"
+ "time"
+
+ "github.com/riverqueue/river/internal/baseservice"
+ "github.com/riverqueue/river/internal/jobcompleter"
+ "github.com/riverqueue/river/internal/jobstats"
+ "github.com/riverqueue/river/internal/util/sliceutil"
+ "github.com/riverque... | Hmm, can we drop this underscore convention? I don't think it's really a thing. Out of 22.5k struct functions in the Go codebase, I did find three instances of one, but they're all kind of weird special cases:
```
$ ag --no-break --nofilename 'func \([^)]+\) [A-Za-z]' | wc -l
22438
$ ag --no-break --nofilena... |
river | github_2023 | go | 379 | riverqueue | brandur | @@ -0,0 +1,271 @@
+package river
+
+import (
+ "context"
+ "fmt"
+ "sync"
+ "time"
+
+ "github.com/riverqueue/river/internal/baseservice"
+ "github.com/riverqueue/river/internal/jobcompleter"
+ "github.com/riverqueue/river/internal/jobstats"
+ "github.com/riverqueue/river/internal/util/sliceutil"
+ "github.com/riverque... | Lots of dead code here. Maybe copy/paste error? |
river | github_2023 | go | 379 | riverqueue | brandur | @@ -0,0 +1,271 @@
+package river
+
+import (
+ "context"
+ "fmt"
+ "sync"
+ "time"
+
+ "github.com/riverqueue/river/internal/baseservice"
+ "github.com/riverqueue/river/internal/jobcompleter"
+ "github.com/riverqueue/river/internal/jobstats"
+ "github.com/riverqueue/river/internal/util/sliceutil"
+ "github.com/riverque... | Can we make this use the normal stop convention instead with `StartInit`? Protects against double starts, but also gives the client a way to check whether all its services are started. |
river | github_2023 | go | 379 | riverqueue | brandur | @@ -0,0 +1,126 @@
+package river
+
+import (
+ "context"
+ "testing"
+ "time"
+
+ "github.com/jackc/pgx/v5"
+ "github.com/riverqueue/river/internal/jobcompleter"
+ "github.com/riverqueue/river/internal/jobstats"
+ "github.com/riverqueue/river/internal/riverinternaltest"
+ "github.com/riverqueue/river/internal/riverinte... | This is racy because the goroutine can run after `subscribeCh` is reset below, which will result in a panic on double-channel close. |
river | github_2023 | go | 376 | riverqueue | brandur | @@ -644,39 +644,83 @@ func Test_Client(t *testing.T) {
t.Run("StopAndCancel", func(t *testing.T) {
t.Parallel()
- client, _ := setup(t)
- jobStartedChan := make(chan int64)
- jobDoneChan := make(chan struct{})
-
- type JobArgs struct {
- JobArgsReflectKind[JobArgs]
+ type testBundle struct {
+ jobDoneCh... | If a test case ends up needing its own setup function, what do you think about denesting it to the stop instead of wiring it in deeper and deeper? It might seem minor, but feels cleaner, requires a lot less indentation, and makes the test case name easier to address because there's fewer segments to find. |
river | github_2023 | go | 376 | riverqueue | brandur | @@ -644,39 +644,83 @@ func Test_Client(t *testing.T) {
t.Run("StopAndCancel", func(t *testing.T) {
t.Parallel()
- client, _ := setup(t)
- jobStartedChan := make(chan int64)
- jobDoneChan := make(chan struct{})
-
- type JobArgs struct {
- JobArgsReflectKind[JobArgs]
+ type testBundle struct {
+ jobDoneCh... | Instead of my usual broad repartee about sleep statements in tests, I'll try to quantify it a little more by showing how slow River's test suite is getting.
Here's a test run of one of my largest packages at work, encompassing the entire API layer:
```
$ gotestsum ./server/api
✓ server/api (2.155s)
DONE 144... |
river | github_2023 | others | 364 | riverqueue | bgentry | @@ -12,7 +12,7 @@ UPDATE river_job SET metadata = '{}' WHERE metadata IS NULL;
ALTER TABLE river_job ALTER COLUMN metadata SET NOT NULL;
-- The 'pending' job state will be used for upcoming functionality:
-ALTER TYPE river_job_state ADD VALUE 'pending' AFTER 'discarded';
+ALTER TYPE river_job_state ADD VALUE IF NOT... | Normally we don’t want to use `IF NOT EXISTS` in these migrations because they indicate a bug or something has been manually manipulated. But, in this case I’m reminded that you can’t safely remove an enum value in Postgres once it’s been added, which [is why it was skipped in the down migration](https://github.com/riv... |
river | github_2023 | go | 237 | riverqueue | bgentry | @@ -29,8 +29,17 @@ type testingT interface {
Logf(format string, args ...any)
}
-// Options for RequireInserted or RequireManyInserted including expectations for
-// various queuing properties that stem from InsertOpts.
+// Options for RequireInserted functions including expectations for various
+// queuing proper... | I don't this behavior is what I would expect here. My intuition (based on how I've used queue assertions for other libraries/ecosystems) is that I'm allowed to be as specific as I desire here, and that the assertion will ensure that no jobs have been inserted which match all of the conditions I specified. If I want, I ... |
river | github_2023 | go | 237 | riverqueue | bgentry | @@ -157,14 +166,117 @@ func requireInsertedErr[TDriver riverdriver.Driver[TTx], TTx any, TArgs river.Jo
}
if opts != nil {
- if !compareJobToInsertOpts(t, jobRow, *opts, -1) {
+ if compareJobToInsertOpts(t, jobRow, opts, -1, false) == compareResCheckFailed {
return nil, nil //nolint:nilnil
}
}
retu... | See my above comment, I think the behavior on this might be backwards.
But as far as the type thing, I would definitely avoid the aliasing option because it results in poorer usability. If we define these types right next to each other, it wouldn't be that hard to keep them lined up. Or alternatively if we can get ... |
river | github_2023 | go | 237 | riverqueue | bgentry | @@ -29,8 +30,18 @@ type testingT interface {
Logf(format string, args ...any)
}
-// Options for RequireInserted or RequireManyInserted including expectations for
-// various queuing properties that stem from InsertOpts.
+// Options for RequireInserted functions including expectations for various
+// queuing proper... | ```suggestion
// In the case of RequireInserted or RequireInsertedMany, if multiple properties
``` |
river | github_2023 | go | 237 | riverqueue | bgentry | @@ -291,22 +414,48 @@ func compareJobToInsertOpts(t testingT, jobRow *rivertype.JobRow, expectedOpts R
return fmt.Sprintf(" (expected job slice index %d)", index)
}
- if expectedOpts.MaxAttempts != 0 && jobRow.MaxAttempts != expectedOpts.MaxAttempts {
- failure(t, "Job with kind '%s'%s max attempts %d not equal... | There's definitely a lot of duplication in these attr comparisons. Do you think it'd be worth extracting a generic helper for these comparable attrs (int, string)? |
river | github_2023 | others | 237 | riverqueue | bgentry | @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
A new `river_queue` table is introduced in the v4 migration for this purpose. Upon startup, every producer in each River `Client` will make an `UPSERT` query to the database to either register the queue as being active... | We missed the release on this so unfortunately this will need to get rebased and pushed to the unreleased section. |
river | github_2023 | go | 324 | riverqueue | brandur | @@ -0,0 +1,137 @@
+package river_test
+
+import (
+ "context"
+ "fmt"
+ "log/slog"
+ "time"
+
+ "github.com/jackc/pgx/v5/pgxpool"
+
+ "github.com/riverqueue/river"
+ "github.com/riverqueue/river/internal/riverinternaltest"
+ "github.com/riverqueue/river/internal/util/slogutil"
+ "github.com/riverqueue/river/riverdriver... | Okay, so one thing with the example tests is that unlike the rest of the suite, they always run sequentially. So by adding this statement, we add exactly +1 second to the runtime of `go test .`, which is already extremely slow.
Instead of this, what do you think about something like:
* Pause the unreliable queue.... |
river | github_2023 | go | 324 | riverqueue | brandur | @@ -0,0 +1,133 @@
+package river_test
+
+import (
+ "context"
+ "fmt"
+ "log/slog"
+ "time"
+
+ "github.com/jackc/pgx/v5/pgxpool"
+
+ "github.com/riverqueue/river"
+ "github.com/riverqueue/river/internal/riverinternaltest"
+ "github.com/riverqueue/river/internal/util/slogutil"
+ "github.com/riverqueue/river/riverdriver... | What do you think about changing this to a `fmt.Printf` and having the output of the example assert its correctness instead?
When it comes to these examples, definitely the fewer LOCs helps to sharpen and clarify. |
river | github_2023 | go | 327 | riverqueue | brandur | @@ -920,20 +926,30 @@ func (c *Client[TTx]) distributeJob(job *rivertype.JobRow, stats *JobStatistics)
}
var event *Event
- switch job.State {
- case rivertype.JobStateCancelled:
- event = &Event{Kind: EventKindJobCancelled, Job: job, JobStats: stats}
- case rivertype.JobStateCompleted:
- event = &Event{Kind: E... | What do you think about just having the producer generate the event rather than having a separate field that's then reassembled into an event post-hoc? See:
https://github.com/riverqueue/river/pull/328/files
Feels a little bit cleaner, and it may help for assembling a full queue object. |
river | github_2023 | go | 327 | riverqueue | brandur | @@ -511,74 +509,73 @@ func Test_Client(t *testing.T) {
config.Queues["alternate"] = QueueConfig{MaxWorkers: 10}
client := newTestClient(t, bundle.dbPool, config)
- jobStartedChan := make(chan int64)
-
- type JobArgs struct {
- JobArgsReflectKind[JobArgs]
- }
-
- AddWorker(client.config.Workers, WorkFunc(f... | Just for the sake of keeping these tests shorter, what do you think of only subscribing to queue-based events here, then we can skip the checks on job events? |
river | github_2023 | go | 327 | riverqueue | brandur | @@ -511,74 +509,73 @@ func Test_Client(t *testing.T) {
config.Queues["alternate"] = QueueConfig{MaxWorkers: 10}
client := newTestClient(t, bundle.dbPool, config)
- jobStartedChan := make(chan int64)
-
- type JobArgs struct {
- JobArgsReflectKind[JobArgs]
- }
-
- AddWorker(client.config.Workers, WorkFunc(f... | This might depend on whether we get the full queue object in the end, but IMO, feels cleaner to have a single assertion on the full event object. More readable, and produces a better error in case of failure too:
```
pauseEvent := riverinternaltest.WaitOrTimeout(t, subscribeChan)
require.Equal(t, &Event{Kind: ... |
river | github_2023 | go | 326 | riverqueue | bgentry | @@ -214,9 +214,9 @@ type AttemptError struct {
// subsequently remove the periodic job with `Remove()`.
type PeriodicJobHandle int
-// Queue is a configuration for a queue that is currently (or recently was) in
+// QueueRow is a configuration for a queue that is currently (or recently was) in
// use by a client.
-... | I'm hesitant to do this. We had to call the job one `JobRow` because we wanted the generic typed variant to be `Job[T]`. However we have no such issue with the queue type and I doubt we will, so it seems unnecessary to clutter this one up with a `*Row` suffix. |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -148,3 +150,13 @@ type AttemptError struct {
// (returned by the use of `Client.PeriodicJobs().Add()`) which can be used to
// subsequently remove the periodic job with `Remove()`.
type PeriodicJobHandle int
+
+// Queue is a configuration for a queue that is currently (or recently was) in
+// use by a client.
+ty... | Just given this is the public facing struct, could we document the properties on this one? |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -44,6 +45,9 @@ const (
PriorityDefault = rivercommon.PriorityDefault
QueueDefault = rivercommon.QueueDefault
QueueNumWorkersMax = 10_000
+
+ queueSettingsPollIntervalDefault = 2 * time.Second
+ queueSettingsReportIntervalDefault = 10 * time.Minute | A couple on this one:
* What do you think about dropping "Settings" out of these names? It makes them a bit of a mouthful, and when I was reading their names, they didn't add anything to explaining what the constants were for (there's no way for the mind to map "settings" to polling for pause/resume state).
* Could... |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -23,6 +23,9 @@ type InsertOpts struct {
// field by River.
Metadata []byte
+ // Pending indicates that the job should be inserted in the `pending` state. | Could you explain this more? I saw the note in the PR description, but a user of the Go API should be able to figure out what this is for by reading the documentation, and even the PR description didn't explain under what circumstances a normal caller might want to set a pending state. |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -1309,10 +1335,23 @@ func (c *Client[TTx]) insert(ctx context.Context, exec riverdriver.Executor, arg
return nil, err
}
- jobInsertRes, err := c.uniqueInserter.JobInsert(ctx, exec, params, uniqueOpts)
+ execTx, err := exec.Begin(ctx) | Should we stick just to `tx` as convention for transaction variables like this? You're using either `tx` or `execTx` for the same thing depending on the specific function (see the block directly below this one for example). |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -1423,6 +1489,93 @@ func (c *Client[TTx]) insertManyParams(params []InsertManyParams) ([]*riverdrive
return insertParams, nil
}
+func (c *Client[TTx]) maybeNotifyInsert(ctx context.Context, execTx riverdriver.ExecutorTx, state rivertype.JobState, queue string) error {
+ if state != rivertype.JobStateAvailable {... | These helper functions are feeling a little on the light side ... only used in one place each, and just 2-3 lines. Creates another jump of indirection when they could probably just be merged into their caller. |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -1423,6 +1489,93 @@ func (c *Client[TTx]) insertManyParams(params []InsertManyParams) ([]*riverdrive
return insertParams, nil
}
+func (c *Client[TTx]) maybeNotifyInsert(ctx context.Context, execTx riverdriver.ExecutorTx, state rivertype.JobState, queue string) error {
+ if state != rivertype.JobStateAvailable {... | This function needs a check on `JobStateAvailable` like the above doesn't it? |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -1423,6 +1489,93 @@ func (c *Client[TTx]) insertManyParams(params []InsertManyParams) ([]*riverdrive
return insertParams, nil
}
+func (c *Client[TTx]) maybeNotifyInsert(ctx context.Context, execTx riverdriver.ExecutorTx, state rivertype.JobState, queue string) error {
+ if state != rivertype.JobStateAvailable {... | IMO refactor this function out. Does nothing but call into the executor (a single function call), used in only one place, but creates another indirection hop. |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -1423,6 +1489,93 @@ func (c *Client[TTx]) insertManyParams(params []InsertManyParams) ([]*riverdrive
return insertParams, nil
}
+func (c *Client[TTx]) maybeNotifyInsert(ctx context.Context, execTx riverdriver.ExecutorTx, state rivertype.JobState, queue string) error {
+ if state != rivertype.JobStateAvailable {... | Just a note that "queue config" is used in some places like this, while "queue settings" is used above.
IMO neither are really that appropriate ... can we call it a "queue state change" or something like that? |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -1528,6 +1681,83 @@ func (c *Client[TTx]) JobListTx(ctx context.Context, tx TTx, params *JobListPara
// client, and can be used to add new ones or remove existing ones.
func (c *Client[TTx]) PeriodicJobs() *PeriodicJobBundle { return c.periodicJobs }
+// QueueGet returns the queue with the given name. If the que... | Okay, sorry to pop a can of worms on this one. I know the intent of the offset pagination is that the set of queues will always be small, but limit/offset pagination is ~never appropriate, and this function's signature locks us into it without a breaking change. It also can't take a sort order (imagine you want to orde... |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -461,6 +458,117 @@ func Test_Client(t *testing.T) {
require.Equal(t, `relation "river_job" does not exist`, pgErr.Message)
})
+ t.Run("PauseAndResume", func(t *testing.T) {
+ t.Parallel()
+
+ config, bundle := setupConfig(t)
+ config.Queues["alternate"] = QueueConfig{MaxWorkers: 10}
+ client := newTestCli... | Could we get another test for the "simple" case that lets you run just a basic pause and unpause? It's often useful to be able to zero in on doing just a basic exercise of a feature to debug something high level. This test exercises everything in one case, and is very verbose so you need to read a lot to understand wha... |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -128,16 +138,47 @@ func (s *JobScheduler) runOnce(ctx context.Context) (*schedulerRunOnceResult, er
ctx, cancelFunc := context.WithTimeout(ctx, 30*time.Second)
defer cancelFunc()
- numScheduled, err := s.exec.JobSchedule(ctx, &riverdriver.JobScheduleParams{
- InsertTopic: string(notifier.NotificationT... | Can we use something more descriptive for this variable like `scheduledJobs`? |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -0,0 +1,162 @@
+package maintenance
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "log/slog"
+ "strings"
+ "time"
+
+ "github.com/riverqueue/river/internal/baseservice"
+ "github.com/riverqueue/river/internal/maintenance/startstop"
+ "github.com/riverqueue/river/internal/rivercommon"
+ "github.com/riverqueue/river/in... | Add "cleaner" to the name of this one, and for the time being, maybe unexport both constants. Neither are needed outside the packages and IMO no reason to ever really make these configurable unless there's a really amazing reason to do so. |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -0,0 +1,162 @@
+package maintenance
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "log/slog"
+ "strings"
+ "time"
+
+ "github.com/riverqueue/river/internal/baseservice"
+ "github.com/riverqueue/river/internal/maintenance/startstop"
+ "github.com/riverqueue/river/internal/rivercommon"
+ "github.com/riverqueue/river/in... | Maybe drop this one down to just `RetentionPeriod`. The additional "Queue" stutters with what's implied by the struct's name. |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -792,6 +795,88 @@ func ExerciseExecutorFull[TTx any](ctx context.Context, t *testing.T, driver riv
require.Equal(t, rivertype.JobStateCompleted, job.State)
require.Equal(t, []string{"tag"}, job.Tags)
})
+
+ // TODO(bgentry): these are probably in the wrong file or location within
+ // the file and shoul... | RE TODO: If you feel it may still be wrong, should probably try to find a new convention for where to put it. Should probably find a way to resolve this TODO before merge since it's fairly trivial. |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -36,6 +36,14 @@ type JobOpts struct {
func Job(ctx context.Context, tb testing.TB, exec riverdriver.Executor, opts *JobOpts) *rivertype.JobRow {
tb.Helper()
+ job, err := exec.JobInsertFull(ctx, JobBuild(tb, opts))
+ require.NoError(tb, err)
+ return job
+}
+
+func JobBuild(tb testing.TB, opts *JobOpts) *riverd... | I was thinking about doing something like this before, but I think we need to establish a different convention, because as is, the naming suggests that this is a factory function for a "job build" entity.
Maybe something like `Job_Build` or `Job_InsertParams`? |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -111,3 +117,26 @@ var seq int64 = 1 //nolint:gochecknoglobals
func nextSeq() int {
return int(atomic.AddInt64(&seq, 1))
}
+
+type QueueOpts struct {
+ Metadata []byte
+ Name *string
+ UpdatedAt *time.Time
+}
+
+func Queue(ctx context.Context, tb testing.TB, exec riverdriver.Executor, opts *QueueOpts) *rive... | Could you change this to?
``` go
Name: ptrutil.ValOrDefaultFunc(opts.Name, func() string { return fmt.Sprintf("queue_%02d", nextSeq()) }),
```
The basic idea with these factory functions is you can call them many times with no (or very few) opts and still get a new valid object back. See migrations above... |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -295,6 +332,51 @@ type insertPayload struct {
Queue string `json:"queue"`
}
+func (p *producer) handleJobControlNotification(workCtx context.Context) func(notifier.NotificationTopic, string) { | Okay, so if I understand correctly, the "job control" topic is shared between (1) job cancel notifications, and (2) queue pause/resume notifications.
It's not super clear to me what these have in common, except that they're both topics used by the producer. But job inserts are also topics shared by the producer, so ... |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -283,6 +318,8 @@ type jobControlAction string
const (
jobControlActionCancel jobControlAction = "cancel"
+ jobControlActionPause jobControlAction = "pause"
+ jobControlActionResume jobControlAction = "resume" | If all these keep sharing, we definitely want a rename of these at least, e.g.:
`Cancel` -> `JobCancel`
`Pause` -> `QueuePause`
`Resume` -> `QueueResume` |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -470,6 +577,84 @@ func (p *producer) handleWorkerDone(job *rivertype.JobRow) {
p.jobResultCh <- job
}
+func (p *producer) pollForSettingChanges(ctx context.Context, lastPaused bool) {
+ ticker := time.NewTicker(p.config.QueueSettingsPollInterval)
+ for {
+ select {
+ case <-ctx.Done():
+ return
+ case <-ti... | Can this be resolved? Maybe just use one of the cancellable sleep helpers with a small jitter even if we're not totally married to the exact timing. Feels better than leaving the TODO in. |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -410,4 +438,126 @@ func testProducer(t *testing.T, makeProducer func(ctx context.Context, t *testin
startstoptest.Stress(ctx, t, producer)
})
+
+ t.Run("QueuePausedBeforeStart", func(t *testing.T) {
+ t.Parallel()
+
+ producer, bundle := setup(t)
+ AddWorker(bundle.workers, &noOpWorker{})
+
+ // TODO: may... | IMO: while there's some argument that jobs should have a fast path because we want them highly performant for benchmarks and the like, one extra insert parameter on queues is going to have ~zero practical performance impact. Maybe just add any desired ones to the normal insert path as optional parameters. |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -0,0 +1,4 @@
+package river
+
+// QueuePauseOpts are optional settings for pausing or unpausing a queue. | I've been struggling with this myself just writing comments here, but for purposes of docs we should try to consolidate on one term. Either "resume" or "unpause", but try to stay consistent. |
river | github_2023 | others | 301 | riverqueue | brandur | @@ -1,5 +1,15 @@
-- name: PGAdvisoryXactLock :exec
SELECT pg_advisory_xact_lock(@key);
--- name: PGNotify :exec
-SELECT pg_notify(@topic, @payload);
\ No newline at end of file
+-- name: PGNotifyMany :exec
+WITH topic_to_notify AS (
+ SELECT
+ concat(current_schema(), '.', @topic::text) AS topic,
+ ... | Minor, but any chance we could try to by convention omit the newlines between CTE cases? Every time I see a `SELECT` like this with a bare line above it, I read it as a standalone expression before realizing there's CTE(s) up there and I have to read upwards to get the whole context. |
river | github_2023 | others | 301 | riverqueue | brandur | @@ -290,11 +297,10 @@ river_job_scheduled AS (
WHERE river_job.id = jobs_to_schedule.id
RETURNING *
)
-SELECT count(*)
-FROM (
- SELECT pg_notify(@insert_topic, json_build_object('queue', queue)::text)
- FROM river_job_scheduled
-) AS notifications_sent;
+SELECT
+ queue,
+ scheduled_at | What do you think about having this return just the full job row instead? There's a minor performance implication, but keeps things more consistent and requires fewer bespoke types in the driver machinery. |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -1646,6 +1729,256 @@ func ExerciseExecutorFull[TTx any](ctx context.Context, t *testing.T, driver riv
require.FailNow(t, "Goroutine didn't finish in a timely manner")
}
}
+
+ t.Run("QueueCreateOrSetUpdatedAt", func(t *testing.T) {
+ t.Run("InsertsANewQueueWithDefaultUpdatedAt", func(t *testing.T) {
+ ... | Could we use some kind of global constant for this, even if it's just for use inside River's internal code?
I was trying to look for how wildcard pause/resume worked, and found this very awkward to search for. It's very short for one, there's no constant so you can't "find references", and "*" is a regex meaningful ... |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -0,0 +1,162 @@
+package maintenance
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "log/slog"
+ "strings"
+ "time"
+
+ "github.com/riverqueue/river/internal/baseservice"
+ "github.com/riverqueue/river/internal/maintenance/startstop"
+ "github.com/riverqueue/river/internal/rivercommon"
+ "github.com/riverqueue/river/in... | Am I understanding correctly that when you use the global pause/resume of "*", you can never pause all queues for more than 24 hours?
Unlike a normal queue, River clients won't report on the global queue "*", so it won't have it's `updated_at` field bumped unless the user pauses/resumes again. So after 24 hours it g... |
river | github_2023 | go | 301 | riverqueue | brandur | @@ -1423,6 +1486,101 @@ func (c *Client[TTx]) insertManyParams(params []InsertManyParams) ([]*riverdrive
return insertParams, nil
}
+func (c *Client[TTx]) maybeNotifyInsert(ctx context.Context, execTx riverdriver.ExecutorTx, state rivertype.JobState, queue string) error {
+ if state != rivertype.JobStateAvailable ... | Small one, but thoughts on using a map instead of slice here? It probably doesn't matter for small numbers of insert many params, but for large ones (e.g. 1k or 10k like the benchmark does), you're allocating quite a large slice here unnecessarily since the cardinality of the queues in use is likely to be a tiny number... |
river | github_2023 | others | 301 | riverqueue | brandur | @@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+⚠️ Version 0.5.0 contains a new database migration, version 4. This migration is backward compatible with any River installation running the v3 migration. Be sure to run the v4 migration prior to depl... | Sorry for the super nit, but mind linking up 54 since it won't be in the rendered changelog.
```suggestion
A useful operational lever is the ability to pause and resume a queue without shutting down clients. In addition to pause/resume being a feature request from [#54](https://github.com/riverqueue/river/pull/54),... |
river | github_2023 | others | 301 | riverqueue | brandur | @@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+⚠️ Version 0.5.0 contains a new database migration, version 4. This migration is backward compatible with any River installation running the v3 migration. Be sure to run the v4 migration prior to depl... | We may want to put together a little upgrade guide on the website because people's familiarity with the last time they migrated may have become long atrophied at this point (i.e. how to use the CLI, the fact that the CLI will need to be updated separately to know about the new migration, etc.). |
river | github_2023 | others | 304 | riverqueue | brandur | @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Changed
+
+- JobList/JobListTx now support querying Jobs by a list of Job Kinds and States (breaking change). Also allows for filtering by specific timestamp values. Thank you Jos Kraaijeveld (@th... | Been using this convention in the other PRs to indicate the breaking change:
```suggestion
- **Breaking change:** JobList/JobListTx now support querying Jobs by a list of Job Kinds and States. Also allows for filtering by specific timestamp values. Thank you Jos Kraaijeveld (@thatjos)! 🙏🏻 [PR #236](https://github... |
river | github_2023 | go | 304 | riverqueue | brandur | @@ -193,6 +190,23 @@ func (p *JobListParams) toDBParams() (*dblist.JobListParams, error) {
return nil, errors.New("invalid sort order")
}
+ if p.sortField == JobListOrderByFinalizedAt {
+ currentNonFinalizedStates := make([]rivertype.JobState, 0, len(p.states))
+ for _, state := range p.states {
+ //nolint:e... | Could we put the non-finalized states into the error message with a `%+v` or something? Just helps make the error quicker to resolve. |
river | github_2023 | others | 308 | riverqueue | bgentry | @@ -7,12 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [0.4.0] - 2024-04-20
+
### Changed
+Version 0.4.0 comes with a number of small breaking changes which we've decided to release all as part of a single version. More breaking changes in one rele... | Should we put a ⚠️ emoji or anything with this? It’s a rare scenario and we want it to be extra visible. |
river | github_2023 | go | 307 | riverqueue | bgentry | @@ -1600,26 +1617,60 @@ func Test_Client_JobList(t *testing.T) {
job5 := testfactory.Job(ctx, t, bundle.exec, &testfactory.JobOpts{State: ptrutil.Ptr(rivertype.JobStateCompleted), ScheduledAt: ptrutil.Ptr(now.Add(-7 * time.Second)), FinalizedAt: ptrutil.Ptr(now.Add(-5 * time.Second))})
job6 := testfactory.Job(ctx... | Do you think it's too much nesting to separate these into separate cases? it's definitely a lot of stuff for a single case IMO. |
river | github_2023 | go | 236 | riverqueue | brandur | @@ -1360,20 +1360,27 @@ func validateQueueName(queueName string) error {
// if err != nil {
// // handle error
// }
-func (c *Client[TTx]) JobList(ctx context.Context, params *JobListParams) ([]*rivertype.JobRow, error) {
+func (c *Client[TTx]) JobList(ctx context.Context, params *JobListParams) ([]*rivertype.JobRo... | Agreed that the code needed to get the next cursor is a little overly verbose at the moment, and furthermore you have to make a `len` check on jobs to make sure you're not indexing a 0-length slice.
``` go
jobs, err := client.JobList(ctx, NewJobListParams().After(JobListCursorFromJob(jobs[len(jobs)-1])))
```
If... |
river | github_2023 | go | 236 | riverqueue | brandur | @@ -15,19 +15,36 @@ import (
// JobListCursor is used to specify a starting point for a paginated
// job list query.
type JobListCursor struct {
- id int64
- kind string
- queue string
- time time.Time
+ id int64
+ kind string
+ queue string
+ sortField JobListOrderByField
+ time time.Time
... | OOC, wasn't this `switch` in `jobListTimeValue` before (and isn't `jobListTimeValue` still in this file?)? Is moving it up just to remove a layer of indirection? |
river | github_2023 | go | 236 | riverqueue | bgentry | @@ -1351,6 +1351,13 @@ func validateQueueName(queueName string) error {
return nil
}
+// JobListResult is the result of a job list operation. It contains a list of
+// jobs and a cursor for fetching the next page of results.
+type JobListResult struct {
+ Jobs []*rivertype.JobRow
+ Cursor *JobListCursor | Not sure it makes sense to output a single `Cursor` field here. There could be a cursor for _any_ of the entries in the `Jobs` list, so with this name it's not clear if it's the start cursor or end cursor.
I doubt there's much use case for the start cursor, and people can always use the `JobListCursorFromJob` functi... |
river | github_2023 | go | 236 | riverqueue | bgentry | @@ -90,12 +113,20 @@ const (
)
// JobListOrderByField specifies the field to sort by.
-type JobListOrderByField int
+type JobListOrderByField string
const (
// JobListOrderByTime specifies that the sort should be by time. The specific
- // time field used will vary by job state.
- JobListOrderByTime JobListOrd... | Can we keep these sorted alphabetically? |
river | github_2023 | go | 306 | riverqueue | bgentry | @@ -111,17 +111,62 @@ type JobRow struct {
Tags []string
}
-// JobState is the state of a job. Jobs start as `available` or `scheduled`, and
-// if all goes well eventually transition to `completed` as they're worked.
+// JobState is the state of a job. Jobs start their lifecycle as either
+// JobStateAvailable or... | Might be worth clarifying the behavior here as this is specifically true when the client doesn’t have an opportunity to log the failure (program crash, hardware failure, or job that never returns from work). |
river | github_2023 | go | 297 | riverqueue | bgentry | @@ -0,0 +1,81 @@
+package rivertype_test
+
+import (
+ "go/ast"
+ "go/parser"
+ "go/token"
+ "os"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+
+ "github.com/riverqueue/river/rivertype"
+)
+
+func TestJobStates(t *testing.T) {
+ t.Parallel()
+
+ jobStates := rivertype.JobStates()
+
+ // One easy check that do... | Great idea! |
river | github_2023 | go | 297 | riverqueue | bgentry | @@ -0,0 +1,81 @@
+package rivertype_test
+
+import (
+ "go/ast"
+ "go/parser"
+ "go/token"
+ "os"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+
+ "github.com/riverqueue/river/rivertype"
+)
+
+func TestJobStates(t *testing.T) {
+ t.Parallel()
+
+ jobStates := rivertype.JobStates()
+
+ // One easy check that do... | typo?
```suggestion
require.FailNow(t, "No values found", "No values found for source file and constant type: %s / %s", srcFile, typeName)
``` |
river | github_2023 | go | 281 | riverqueue | bgentry | @@ -180,34 +180,47 @@ func runNewTestClient(ctx context.Context, t *testing.T, config *Config) *Client
return client
}
-func Test_Client(t *testing.T) {
+func Test_Client_Standard(t *testing.T) { | were you originally renaming this because you planned to have a separate poll-only test block? As of now it looks like you just added a single case in here and don't need to rename this. |
river | github_2023 | go | 281 | riverqueue | bgentry | @@ -13,13 +13,19 @@ import (
"github.com/riverqueue/river/internal/notifier"
"github.com/riverqueue/river/internal/rivercommon"
"github.com/riverqueue/river/internal/util/dbutil"
+ "github.com/riverqueue/river/internal/util/valutil"
"github.com/riverqueue/river/riverdriver"
)
const (
- electInterval ... | It goes away with app-level notifications anyway. Will be a small conflict but no worries. |
river | github_2023 | go | 281 | riverqueue | bgentry | @@ -210,7 +210,7 @@ func (p *producer) StartWorkContext(fetchCtx, workCtx context.Context) error {
fetchLimiter.Call()
}
// TODO(brandur): Get rid of this retry loop after refactor.
- insertSub, err = notifier.ListenRetryLoop(fetchCtx, &p.BaseService, p.config.Notifier, notifier.NotificationTopicInsert, hand... | comment above still relevant? |
river | github_2023 | go | 281 | riverqueue | bgentry | @@ -241,7 +241,7 @@ func (p *producer) StartWorkContext(fetchCtx, workCtx context.Context) error {
)
}
// TODO(brandur): Get rid of this retry loop after refactor.
- jobControlSub, err = notifier.ListenRetryLoop(fetchCtx, &p.BaseService, p.config.Notifier, notifier.NotificationTopicJobControl, handleJobContr... | comment above still relevant? |
river | github_2023 | go | 288 | riverqueue | bgentry | @@ -0,0 +1,189 @@
+package river
+
+import (
+ "time"
+
+ "github.com/riverqueue/river/internal/dbunique"
+ "github.com/riverqueue/river/internal/maintenance"
+ "github.com/riverqueue/river/internal/util/sliceutil"
+ "github.com/riverqueue/river/riverdriver"
+ "github.com/riverqueue/river/rivertype"
+)
+
+// PeriodicSc... | Any particular reason for the `All` suffix? I feel like `RemoveMany` would suffice here. |
river | github_2023 | go | 288 | riverqueue | bgentry | @@ -264,39 +259,226 @@ func TestPeriodicJobEnqueuer(t *testing.T) {
svc, _ := setup(t)
- svc.periodicJobs = []*PeriodicJob{
- {ScheduleFunc: periodicIntervalSchedule(time.Microsecond), ConstructorFunc: jobConstructorFunc("periodic_job_1us", false)},
- }
+ svc.Add(&PeriodicJob{ScheduleFunc: periodicIntervalS... | missed TODO? |
river | github_2023 | go | 284 | riverqueue | bgentry | @@ -168,7 +168,11 @@ func (s *PeriodicJobEnqueuer) Start(ctx context.Context) error {
continue
}
- periodicJob.nextRunAt = periodicJob.ScheduleFunc(now)
+ // Although we may have inserted a new job a little
+ // assertively due to the margin applied above, try to stay | ```suggestion
// preemptively due to the margin applied above, try to stay
``` |
river | github_2023 | go | 280 | riverqueue | bgentry | @@ -44,12 +44,24 @@ func TestReindexer(t *testing.T) {
svc := NewReindexer(archetype, &ReindexerConfig{
ScheduleFunc: fromNow(500 * time.Millisecond),
}, bundle.exec)
+ svc.StaggerStartupDisable(true)
svc.TestSignals.Init()
t.Cleanup(svc.Stop)
return svc, bundle
}
+ runImmediatelyThanOnceAnHou... | ```suggestion
runImmediatelyThenOnceAnHour := func() func(time.Time) time.Time {
``` |
river | github_2023 | go | 280 | riverqueue | bgentry | @@ -44,12 +44,24 @@ func TestReindexer(t *testing.T) {
svc := NewReindexer(archetype, &ReindexerConfig{
ScheduleFunc: fromNow(500 * time.Millisecond),
}, bundle.exec)
+ svc.StaggerStartupDisable(true)
svc.TestSignals.Init()
t.Cleanup(svc.Stop)
return svc, bundle
}
+ runImmediatelyThanOnceAnHou... | does `TickerWithInitialTick` not work here? |
river | github_2023 | go | 280 | riverqueue | bgentry | @@ -48,14 +41,6 @@ type Archetype struct {
TimeNowUTC func() time.Time
}
-// WithSleepDisabled disables sleep in services that are using `BaseService`'s
-// `CancellableSleep` functions and returns the archetype for convenience. Use
-// of this is only appropriate in tests.
-func (a *Archetype) WithSleepDisabled()... | It does seem like a bit of a step back to spread out the problematic behavior into more places, but whatever you think is the best option here. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.