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 | go | 266 | riverqueue | bgentry | @@ -1,26 +1,403 @@
+// testdbman is a command-line tool for managing the test databases used by
+// parallel tests and the sample applications.
package main
import (
+ "context"
+ "errors"
+ "flag"
"fmt"
+ "io"
"os"
+ "runtime"
+ "slices"
+ "strings"
+ "time"
- "github.com/spf13/cobra"
+ "github.com/jackc/pgx... | This comment is probably better placed above line 138 where the `numDBs` is calculated |
river | github_2023 | go | 272 | riverqueue | bgentry | @@ -575,146 +571,154 @@ func NewClient[TTx any](driver riverdriver.Driver[TTx], config *Config) (*Client
// jobs, but will also cancel the context for any currently-running jobs. If
// using StopAndCancel, there's no need to also call Stop.
func (c *Client[TTx]) Start(ctx context.Context) error {
- if !c.config.will... | It might be more readable and easily debuggable if some of these closures were split into internal client methods. Thinking in particular of the potential for a trace to have anonymous goroutines rather than named methods.
Not a huge concern but it might be worth trying to shuffle some of this around to improve the ... |
river | github_2023 | go | 272 | riverqueue | bgentry | @@ -2564,8 +2574,8 @@ func Test_Client_InsertTriggersImmediateWork(t *testing.T) {
ctx := context.Background()
require := require.New(t)
- ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
- t.Cleanup(cancel)
+ // ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
+ // t.Cleanup(cancel) | Mistakenly commented? |
river | github_2023 | go | 272 | riverqueue | bgentry | @@ -79,27 +100,63 @@ func (s *BaseStartStop) StartInit(ctx context.Context) (context.Context, bool, c
s.started = true
s.stopped = make(chan struct{})
- ctx, s.cancelFunc = context.WithCancel(ctx)
+ ctx, s.cancelFunc = context.WithCancelCause(ctx)
return ctx, true, s.stopped
}
// Stop is an automatically ... | ```suggestion
// should be avoided unless there's an exceptional reason not to because Stop
``` |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -69,7 +69,7 @@ func jobStatisticsFromInternal(stats *jobstats.JobStatistics) *JobStatistics {
// The maximum size of the subscribe channel. Events that would overflow it will
// be dropped.
-const subscribeChanSize = 100
+const subscribeChanSize = 50_000 | I was wondering earlier if this would be an issue with the way you were now measuring. It’s unlikely someone would hit this in practice but I suppose it’s still a bit of a wart with the current fixed size buffered channel for subscriptions. |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -56,125 +64,290 @@ type InlineJobCompleter struct {
wg sync.WaitGroup
}
-func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor) *InlineJobCompleter {
- return baseservice.Init(archetype, &InlineJobCompleter{
+func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor... | Unfortunately I think this change is a pretty substantial degradation. With this PR we're now debouncing up to 100ms, meaning jobs could have up to 100ms of randomly distributed padding added to their `finalized_at`, making it so `attempted_at - finalized_at` is no longer representative of their duration (at least not ... |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -656,18 +677,21 @@ func (c *Client[TTx]) signalStopComplete(ctx context.Context) {
producer.Stop()
}
- // Stop all mainline services where stop order isn't important. Contains the
- // elector and notifier, amongst others.
- startstop.StopAllParallel(c.services)
-
- // Once the producers have all finished, we... | oh yeah, there's probably no reason for this not to stop earlier. Well, maybe it should wait until after the elector has given up any leadership it may hold? 🤔 I guess it's fine if not, worst case they skip a cycle that's about to happen but somebody else will pick it up, right? Is that true of all maintenance service... |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -762,7 +785,41 @@ func (c *Client[TTx]) Stopped() <-chan struct{} {
// versions. If new event kinds are added, callers will have to explicitly add
// them to their requested list and ensure they can be handled correctly.
func (c *Client[TTx]) Subscribe(kinds ...EventKind) (<-chan *Event, func()) {
- for _, kind :... | I guess we don't care about max? if you want to be dumb go right ahead...? |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -132,13 +145,30 @@ func (b *Benchmarker[TTx]) Run(ctx context.Context) error {
case <-shutdown:
return
- case <-subscribeChan:
- numJobsLeft.Add(-1)
- numJobsWorked := numJobsWorked.Add(1)
+ case event := <-subscribeChan:
+ if event == nil { // Closed channel.
+ b.logger.InfoContext(ctx, ... | should we count and log these for debug purposes? |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -56,125 +63,299 @@ type InlineJobCompleter struct {
wg sync.WaitGroup
}
-func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor) *InlineJobCompleter {
- return baseservice.Init(archetype, &InlineJobCompleter{
+func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor... | Hmm, is this an appropriate context to be passing down and respecting the deadline on? Isn't this `ctx` the job's execution context, which may be cancelled (including by a remote cancellation attempt)?
I feel like the only place it would make sense to be used is in the inline completer. The async one should probably... |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -56,125 +63,299 @@ type InlineJobCompleter struct {
wg sync.WaitGroup
}
-func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor) *InlineJobCompleter {
- return baseservice.Init(archetype, &InlineJobCompleter{
+func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor... | This context is unused, but do you think it should maybe in some way be a parent to any completion attempts in here? Actually, I'm second-guessing myself in realtime. Even in the case of an aggressive shutdown, we still don't want to shut down until the completer has finished its work. So IMO these completion attempts ... |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -56,125 +63,299 @@ type InlineJobCompleter struct {
wg sync.WaitGroup
}
-func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor) *InlineJobCompleter {
- return baseservice.Init(archetype, &InlineJobCompleter{
+func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor... | ```suggestion
WaitingAt time.Time // when job was submitted for completion
``` |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -56,125 +63,299 @@ type InlineJobCompleter struct {
wg sync.WaitGroup
}
-func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor) *InlineJobCompleter {
- return baseservice.Init(archetype, &InlineJobCompleter{
+func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor... | Is it preferable to wait until the end of the timer window once we have enough jobs to fill a batch, or should we dispatch it ~immediately when we hit this threshold and reset the timer?
Doesn't have to be part of this PR, but might be worth refactoring if you think it could be straightforward to do so. IMO if we al... |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -56,125 +63,299 @@ type InlineJobCompleter struct {
wg sync.WaitGroup
}
-func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor) *InlineJobCompleter {
- return baseservice.Init(archetype, &InlineJobCompleter{
+func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor... | Doesn't this `DebouncedChan` type fire on the leading edge? So that means we will always submit a batch of 1 before then waiting to collect additional jobs? Doesn't seem ideal if so. |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -56,125 +63,299 @@ type InlineJobCompleter struct {
wg sync.WaitGroup
}
-func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor) *InlineJobCompleter {
- return baseservice.Init(archetype, &InlineJobCompleter{
+func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor... | Slightly misnamed IMO because it's not _inserting_ anything. Maybe submit, update, or handle sub batch? |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -56,125 +63,299 @@ type InlineJobCompleter struct {
wg sync.WaitGroup
}
-func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor) *InlineJobCompleter {
- return baseservice.Init(archetype, &InlineJobCompleter{
+func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor... | so if a single sub batch fails after 4 attempts, we immediately return an error and give up on all remaining jobs in the batch? That feels a bit risky 🤔
Also is there any kind of backpressure to stop the client from fetching more jobs if the completer is filling up and can't complete all the jobs it already has li... |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -56,125 +63,299 @@ type InlineJobCompleter struct {
wg sync.WaitGroup
}
-func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor) *InlineJobCompleter {
- return baseservice.Init(archetype, &InlineJobCompleter{
+func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor... | Can we instead make sure the completer is started & good to go before we even start working jobs? Seems better than having this channel receive on every single completion IMO. And the slight increase in startup time also seems worth it to be as sure as possible that jobs are ready to be worked successfully. |
river | github_2023 | others | 258 | riverqueue | bgentry | @@ -23,10 +24,9 @@ require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
- github.com/oklog/ulid/v2 v2.1.0 // indirect
+ github.com/lmittmann/tint v1.0.4 // indirect | Looks solid! I think I'm gonna pull this into my riverdemo app too. |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -612,19 +612,40 @@ func (c *Client[TTx]) Start(ctx context.Context) error {
return err
}
- // Receives job complete notifications from the completer and distributes
- // them to any subscriptions.
- c.completer.Subscribe(c.distributeJobCompleterCallback)
+ if c.completer != nil {
+ // The completer is part o... | Missed the rename in this comment:
```suggestion
// TODO(brandur): Reevaluate the use of fetchCtx here. It's
``` |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -94,17 +96,17 @@ func (b *Benchmarker[TTx]) Run(ctx context.Context) error {
// values against the wall, they perform quite well. Much better than
// the client's default values at any rate.
FetchCooldown: 2 * time.Millisecond,
- FetchPollInterval: 5 * time.Millisecond,
+ FetchPollInterval: 20 * time.... | did you find that this gave you better throughput at 20ms vs 5ms? |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -56,170 +60,468 @@ type InlineJobCompleter struct {
wg sync.WaitGroup
}
-func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor) *InlineJobCompleter {
- return baseservice.Init(archetype, &InlineJobCompleter{
+func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor... | bit of awkward phrasing in here, probably worth tweaking |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -56,170 +60,468 @@ type InlineJobCompleter struct {
wg sync.WaitGroup
}
-func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor) *InlineJobCompleter {
- return baseservice.Init(archetype, &InlineJobCompleter{
+func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor... | We may want to bump this a bit. 7 seconds could be just a short connectivity blip, so it seems a bit extreme to potentially allow bulk data loss in that situation.
Is there harm from increasing it? Of course the client won't be able to keep working new jobs if it hits the max backlog because we're stuck retrying, bu... |
river | github_2023 | go | 258 | riverqueue | bgentry | @@ -56,170 +60,468 @@ type InlineJobCompleter struct {
wg sync.WaitGroup
}
-func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor) *InlineJobCompleter {
- return baseservice.Init(archetype, &InlineJobCompleter{
+func NewInlineCompleter(archetype *baseservice.Archetype, exec PartialExecutor... | This is somewhat pgx-specific, isn't it? Do we need a driver error type for this? |
river | github_2023 | go | 264 | riverqueue | bgentry | @@ -644,17 +644,30 @@ func (c *Client[TTx]) Start(ctx context.Context) error {
}()
}
- c.runProducers(fetchNewWorkCtx, workCtx)
- go c.signalStopComplete(workCtx)
+ for _, producer := range c.producersByQueueName {
+ producer := producer
+
+ if err := producer.StartWorkContext(fetchNewWorkCtx, workCtx); err !=... | this is just for the elector now, isn't it? |
river | github_2023 | go | 264 | riverqueue | bgentry | @@ -385,18 +445,13 @@ func (p *producer) startNewExecutors(workCtx context.Context, jobs []*rivertype.
p.addActiveJob(job.ID, executor)
go executor.Execute(jobCtx)
- // TODO:
- // Errors can be recorded synchronously before the Executor slot is considered
- // available.
- //
- // Successful jobs can be se... | thanks, this is quite outdated 😆 |
river | github_2023 | go | 264 | riverqueue | bgentry | @@ -136,63 +135,111 @@ func Test_Producer_CanSafelyCompleteJobsWhileFetchingNewOnes(t *testing.T) {
case <-ctx.Done():
t.Error("timed out waiting for last job to run")
}
- wg.Wait()
}
-func Test_Producer_Run(t *testing.T) {
+func TestProducer_PollOnly(t *testing.T) {
t.Parallel()
- ctx := context.Backgrou... | ```suggestion
// conflict with jobs being inserted in test cases.
``` |
river | github_2023 | go | 263 | riverqueue | bgentry | @@ -62,206 +89,294 @@ type Elector struct {
// NewElector returns an Elector using the given adapter. The name should correspond
// to the name of the database + schema combo and should be shared across all Clients
// running with that combination. The id should be unique to the Client.
-func NewElector(archetype *b... | typo here:
> We only care about resignations on because |
river | github_2023 | go | 263 | riverqueue | bgentry | @@ -62,206 +89,294 @@ type Elector struct {
// NewElector returns an Elector using the given adapter. The name should correspond
// to the name of the database + schema combo and should be shared across all Clients
// running with that combination. The id should be unique to the Client.
-func NewElector(archetype *b... | `Info` level might be a bit noisy for this running every 5 seconds on every worker and it being a completely benign/expected scenario, maybe `Debug`?
```suggestion
e.Logger.Debug(e.Name+": Leadership bid was unsuccessful (not an error)", "client_id", e.clientID)
``` |
river | github_2023 | go | 263 | riverqueue | bgentry | @@ -62,206 +89,294 @@ type Elector struct {
// NewElector returns an Elector using the given adapter. The name should correspond
// to the name of the database + schema combo and should be shared across all Clients
// running with that combination. The id should be unique to the Client.
-func NewElector(archetype *b... | there's a potential leaking of timers here, but only if resignations are happening frequently |
river | github_2023 | go | 263 | riverqueue | bgentry | @@ -62,206 +89,294 @@ type Elector struct {
// NewElector returns an Elector using the given adapter. The name should correspond
// to the name of the database + schema combo and should be shared across all Clients
// running with that combination. The id should be unique to the Client.
-func NewElector(archetype *b... | Is this inverted? The message seems to align with when the node _lost_ its leadership |
river | github_2023 | go | 263 | riverqueue | bgentry | @@ -442,6 +442,8 @@ func (n *Notifier) Listen(ctx context.Context, topic NotificationTopic, notifyFu
}
n.subscriptions[topic] = append(existingSubs, sub)
+ n.Logger.InfoContext(ctx, n.Name+": Added subscription", "new_num_subscriptions", len(n.subscriptions[topic]), "topic", topic) | This one also feels like it should maybe be a `Debug` level given it's indicative of healthy operation and pretty low level, thoughts? |
river | github_2023 | go | 254 | riverqueue | bgentry | @@ -0,0 +1,424 @@
+package riverbench
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "log/slog"
+ "os"
+ "os/signal"
+ "sync/atomic"
+ "syscall"
+ "time"
+
+ "github.com/riverqueue/river"
+ "github.com/riverqueue/river/riverdriver"
+)
+
+type Benchmarker[TTx any] struct {
+ driver riverdriver.Driver[TTx]
+ duration... | aaaaWe'd probably want to make this `MaxWorkers` param an argument to the bench command. Setting it to 10k is probably not realistic, and it would probably be useful to play around with different input values to find the sweet spot on throughput.
The fetch cooldown is another attr that's probably worth setting up as... |
river | github_2023 | others | 254 | riverqueue | bgentry | @@ -22,9 +23,10 @@ require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
- github.com/riverqueue/river/riverdriver v0.0.17 // indirect
+ github.com/oklog/ulid/v2 v2.1.0 // indirect | seems like this is outdated diff? |
river | github_2023 | go | 253 | riverqueue | bgentry | @@ -114,8 +114,18 @@ func (e *Elector) Run(ctx context.Context) {
}
}
- subscription := e.notifier.Listen(notifier.NotificationTopicLeadership, handleNotification)
- defer subscription.Unlisten()
+ sub, err := e.notifier.Listen(ctx, notifier.NotificationTopicLeadership, handleNotification)
+ if err != nil {
+ i... | I think the challenge is that it's probably desirable to have the client fail to start if any of its critical subprocesses fail to start correctly at initial boot, however if those subprocesses fail at any other point they should enter into a graceful exponential backoff loop to try and get healthy again.
This is th... |
river | github_2023 | go | 253 | riverqueue | bgentry | @@ -24,189 +28,327 @@ const (
type NotifyFunc func(topic NotificationTopic, payload string)
type Subscription struct {
- creationTime time.Time
- topic NotificationTopic
notifyFunc NotifyFunc
-
- unlistenOnce *sync.Once
notifier *Notifier
+ topic NotificationTopic
+ unlistenOnce sync.Once
}... | doesn't `attempt` need to get reset at some point once a connection is successfully established? Otherwise it will continually increment every time there's a conn failure or reconnect, meaning you could have a very long backoff retry if the program has been running for a long time even if there hasn't been an issue for... |
river | github_2023 | go | 253 | riverqueue | bgentry | @@ -24,189 +28,327 @@ const (
type NotifyFunc func(topic NotificationTopic, payload string)
type Subscription struct {
- creationTime time.Time
- topic NotificationTopic
notifyFunc NotifyFunc
-
- unlistenOnce *sync.Once
notifier *Notifier
+ topic NotificationTopic
+ unlistenOnce sync.Once
}... | Is it safe to use a background context with no timeout here? I'm guessing not, because this underlying code:
https://github.com/riverqueue/river/blob/35ee45ee57e15b91eb1f722c4bf6ff69c003779d/riverdriver/riverpgxv5/river_pgx_v5_driver.go#L524-L530
Could hang forever if the context never times out and there isn't s... |
river | github_2023 | go | 253 | riverqueue | bgentry | @@ -220,122 +362,175 @@ func (n *Notifier) runOnce(ctx context.Context) error {
// * Wait for notifications
// * Ping conn if 5 seconds have elapsed between notifications to keep it alive
- // * Manage listens/unlistens on conn
+ // * Manage listens/unlistens on conn (waitInterruptChan)
// * If any errors are e... | I don't think this behavior aligns with how the users of the notifier are designed today. I believe they all expect that once they call `Listen(topic)`, the notifier will do its best to make sure that `topic` is listened to until the subscriber calls `Unlisten` on the subscription. This is the case regardless of what e... |
river | github_2023 | go | 246 | riverqueue | bgentry | @@ -475,12 +475,14 @@ func (l *Listener) Close(ctx context.Context) error {
return nil
}
- if err := l.conn.Conn().Close(ctx); err != nil {
- return err
- } | Man, I noticed [this change](https://github.com/riverqueue/river/pull/212/files#diff-445bd06e41eab3a8a89576b7cda31b0e834bbefa4fa969af11c1ce17766b1cceL149) when I reviewed the mega-PR, should have said something 😞 |
river | github_2023 | go | 250 | riverqueue | bgentry | @@ -475,14 +475,10 @@ func (l *Listener) Close(ctx context.Context) error {
return nil
}
- err := l.conn.Conn().Close(ctx)
-
- // Regardless of the error state returned above, always release and unset
- // the listener's local connection. | I'm not actually sure this is a good idea and I don't think we want to return the conn to the pool. If there are `LISTEN` subscriptions active which weren't properly `UNLISTEN`'d, the conn may still receive additional notifications that could interfere with other operations on it.
For pgbouncer compatibility reasons... |
river | github_2023 | go | 250 | riverqueue | bgentry | @@ -34,10 +39,144 @@ func TestNew(t *testing.T) {
})
}
+func TestListener_Close(t *testing.T) {
+ t.Parallel()
+
+ ctx := context.Background()
+
+ t.Run("NoOpWithoutConn", func(t *testing.T) {
+ t.Parallel()
+
+ listener := &Listener{dbPool: testPool(ctx, t, nil)}
+ require.Nil(t, listener.conn)
+ require.NoEr... | not more packages 😩 |
river | github_2023 | others | 229 | riverqueue | bgentry | @@ -22,13 +22,6 @@ sql:
rename:
river_job_state: "JobState"
- river_job_state_available: "JobStateAvailable"
- river_job_state_cancelled: "JobStateCancelled"
- river_job_state_completed: "JobStateCompleted"
- river_job_state_discarded: "JobStateDiscarded"
- ... | one less thing to have to fix when I get that pending state added soon. |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -117,7 +133,178 @@ type ExecutorTx interface {
Rollback(ctx context.Context) error
}
+// Listner listens for notifications. In Postgres, this is a database connection | ```suggestion
// Listener listens for notifications. In Postgres, this is a database connection
``` |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -332,7 +331,7 @@ var (
// ErrNotFound is returned when a query by ID does not match any existing
// rows. For example, attempting to cancel a job that doesn't exist will
// return this error.
- ErrNotFound = errors.New("not found")
+ ErrNotFound = rivertype.ErrNotFound | Got thrown off at first trying to figure out how you were still returning the top level `ErrNotFound` but now I see it. I think this makes sense—if it's the same actual error value across packages then it will always be considered equal and `errors.Is()` checks will succeed, right?
Only downside is the extra layer o... |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -1052,44 +1040,28 @@ func (c *Client[TTx]) JobCancel(ctx context.Context, jobID int64) (*rivertype.Jo
// Returns the up-to-date JobRow for the specified jobID if it exists. Returns
// ErrNotFound if the job doesn't exist.
func (c *Client[TTx]) JobCancelTx(ctx context.Context, tx TTx, jobID int64) (*rivertype.JobR... | I love that these are refactored to share all their logic, thank you! |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -38,10 +44,13 @@ func New(dbPool *pgxpool.Pool) *Driver {
return &Driver{dbPool: dbPool, queries: dbsqlc.New()}
}
-func (d *Driver) GetDBPool() *pgxpool.Pool { return d.dbPool }
-func (d *Driver) GetExecutor() riverdriver.Executor { return &Executor{d.dbPool, dbsqlc.New()} }
-fu... | I'm surprised golangci-lint doesn't complain about initializing structs without named fields. Do you think we should stop doing that or are you not worried about it? |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -117,7 +133,178 @@ type ExecutorTx interface {
Rollback(ctx context.Context) error
}
+// Listner listens for notifications. In Postgres, this is a database connection
+// where `LISTEN` has been run.
+//
+// API is not stable. DO NOT IMPLEMENT.
+type Listener interface {
+ Close(ctx context.Context) error
+ Con... | I assume the reason you've exposed additional fields here that aren't meant to be available on normal inserts (`Finalized`, `Attempt`, etc) is to facilitate testing without a bunch of specialized test insert helpers?
I'm a bit concerned seeing all the bulk inserts now referencing these fields which were previously m... |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -1143,10 +1099,10 @@ func (c *Client[TTx]) ID() string {
return c.config.ID
}
-func insertParamsFromArgsAndOptions(args JobArgs, insertOpts *InsertOpts) (*dbadapter.JobInsertParams, error) {
+func insertParamsFromArgsAndOptions(args JobArgs, insertOpts *InsertOpts) (*riverdriver.JobInsertParams, *dbunique.Uniqu... | haven't seen a triple return value in awhile 😆 |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -2577,25 +2604,29 @@ func Test_Client_JobCompletion(t *testing.T) {
t.Parallel()
require := require.New(t)
- var dbPool *pgxpool.Pool
now := time.Now().UTC()
- config := newTestConfig(t, func(ctx context.Context, job *Job[callbackArgs]) error {
- _, err := queries.JobSetState(ctx, dbPool, dbsqlc.JobSe... | Hmm, I don't love that we have to re-transmit the entire error list over the wire every time we append one. For jobs that have been run many times this could start to be a lot of extra overhead.
Was this necessitated by limitations in the underlying drivers or something? |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -3246,16 +3289,15 @@ func TestInsertParamsFromJobArgsAndOptions(t *testing.T) {
t.Run("Defaults", func(t *testing.T) {
t.Parallel()
- insertParams, err := insertParamsFromArgsAndOptions(noOpArgs{}, nil)
+ insertParams, _, err := insertParamsFromArgsAndOptions(noOpArgs{}, nil)
require.NoError(t, err)
r... | did we add coverage for the returned unique opts somewhere else? |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -1,44 +0,0 @@
-package dbsqlc
-
-import (
- "github.com/riverqueue/river/internal/util/sliceutil"
- "github.com/riverqueue/river/rivertype"
-)
-
-func JobRowFromInternal(internal *RiverJob) *rivertype.JobRow {
- return &rivertype.JobRow{
- ID: internal.ID,
- Attempt: max(int(internal.Attempt), 0),
- ... | Do we have any follow-ups to track from the loss of this note? Not sure how deeply we ever looked into ensuring there were no TZ related issues. |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -293,3 +309,39 @@ func (e *Elector) notifySubscribers(isLeader bool) {
}
}
}
+
+const deadlineTimeout = 5 * time.Second
+
+// LeaderAttemptElect attempts to elect a leader for the given name. The
+// bool alreadyElected indicates whether this is a potential reelection of
+// an already-elected leader. If the e... | Should this be unexported? Can't see it used externally afaict. |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -165,7 +166,11 @@ func (e *Elector) gainLeadership(ctx context.Context, leadershipNotificationChan
}
func (e *Elector) attemptElect(ctx context.Context) (bool, error) {
- elected, err := e.adapter.LeadershipAttemptElect(ctx, false, e.name, e.id, e.interval)
+ elected, err := LeaderAttemptElect(ctx, e.exec, false... | Welp, I missed this in #217, but we should use the TTL padding here too 🤦♂️ |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -0,0 +1,114 @@
+package leadership
+
+import (
+ "context"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/require"
+
+ "github.com/riverqueue/river/internal/riverinternaltest"
+ "github.com/riverqueue/river/internal/riverinternaltest/testfactory"
+ "github.com/riverqueue/river/internal/util/ptrutil"
+ "github... | On the topic of test coverage here, I'm realizing that all these tests are within a transaction and we won't be able to properly test the DB queries that use `now()` as a result. We'll either need to avoid using `now()` and pass in the time, or have some higher level integration-type tests which operate on a full DB in... |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -127,25 +118,25 @@ func (s *Scheduler) Start(ctx context.Context) error { //nolint:dupl
}
type schedulerRunOnceResult struct {
- NumCompletedJobsScheduled int64
+ NumCompletedJobsScheduled int
}
func (s *Scheduler) runOnce(ctx context.Context) (*schedulerRunOnceResult, error) {
res := &schedulerRunOnceResu... | oh come on, you're not gonna schedule 2.1 billion jobs in one query?? 😢 |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -220,6 +223,15 @@ func (p *JobListParams) First(count int) *JobListParams {
return result
}
+// Kinds returns an updated filter set that will only return jobs of the given
+// kinds.
+func (p *JobListParams) Kinds(kinds ...string) *JobListParams {
+ result := p.copy()
+ result.kinds = make([]string, 0, len(kind... | A bit hard to tell, but I think this addition might be missing test coverage? |
river | github_2023 | others | 212 | riverqueue | bgentry | @@ -1,14 +1,7 @@
module github.com/riverqueue/river/riverdriver
-go 1.21
+go 1.21.4
-require github.com/jackc/pgx/v5 v5.5.0
+replace github.com/riverqueue/river/rivertype => ../rivertype | Is this meant to stay in here? |
river | github_2023 | others | 212 | riverqueue | bgentry | @@ -14,11 +20,40 @@ sql:
emit_methods_with_db_argument: true
emit_result_struct_pointers: true
+ rename:
+ river_job_state: "JobState"
+ river_job_state_available: "JobStateAvailable"
+ river_job_state_cancelled: "JobStateCancelled"
+ river_job_state_comple... | To be fixed 🔜 |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -0,0 +1,96 @@
+// Package testfactory provides low level helpers for inserting records directly
+// into the database.
+package testfactory
+
+import (
+ "context"
+ "sync/atomic"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/require"
+
+ "github.com/riverqueue/river/internal/rivercommon"
+ "github.com/river... | we should have done this a long time ago 😆 |
river | github_2023 | others | 212 | riverqueue | bgentry | @@ -0,0 +1,315 @@
+CREATE TYPE river_job_state AS ENUM(
+ 'available',
+ 'cancelled',
+ 'completed',
+ 'discarded',
+ 'retryable',
+ 'running',
+ 'scheduled'
+);
+
+CREATE TABLE river_job(
+ id bigserial PRIMARY KEY,
+ args jsonb,
+ attempt smallint NOT NULL DEFAULT 0,
+ attempted_at ti... | Missed the alphabetization on these two |
river | github_2023 | others | 212 | riverqueue | bgentry | @@ -0,0 +1,315 @@
+CREATE TYPE river_job_state AS ENUM(
+ 'available',
+ 'cancelled',
+ 'completed',
+ 'discarded',
+ 'retryable',
+ 'running',
+ 'scheduled'
+);
+
+CREATE TABLE river_job(
+ id bigserial PRIMARY KEY,
+ args jsonb,
+ attempt smallint NOT NULL DEFAULT 0,
+ attempted_at ti... | Per earlier conversation, I think there's a good argument for minimizing these two insert queries so that they only have fields which are intended to be set during initial insert. We can save the fields like `errors`, `finalized_at`, `attempt`, and `attempted_at` for a separate insert function only used by internal tes... |
river | github_2023 | others | 212 | riverqueue | bgentry | @@ -0,0 +1,30 @@
+-- name: JobInsertMany :copyfrom
+INSERT INTO river_job(
+ args,
+ attempt,
+ attempted_at,
+ errors,
+ finalized_at, | Likewise on eliminating unnecessary fields from this `JobInsertMany` query. The good thing is the extra fields will _only_ need to be specified on the all-fields test helper insert query, whereas `JobInsert` and `JobInsertMany` will have shorter lists of fields. Plus we will only need a non-copy (one-at-a-time) API for... |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -55,22 +53,13 @@ func JobCompleteTx[TDriver riverdriver.Driver[TTx], TTx any, TArgs JobArgs](ctx
return nil, errors.New("job must be running")
}
- var (
- driver TDriver
- queries = &dbsqlc.Queries{}
- )
-
- internal, err := queries.JobSetState(ctx, driver.UnwrapTx(tx), dbsqlc.JobSetStateParams{
- ID: ... | This is a small behavioral change due to the differences in the underlying queries, but I don't think it's a big issue. You really shouldn't be using this to set a job as complete if it's not actually running. |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -99,34 +447,133 @@ func (t *ExecutorTx) Rollback(ctx context.Context) error {
return t.tx.Rollback(ctx)
}
-func interpretError(err error) error {
- if errors.Is(err, pgx.ErrNoRows) {
- return riverdriver.ErrNoRows
+type Listener struct {
+ conn *pgxpool.Conn
+ dbPool *pgxpool.Pool
+ mu sync.RWMutex
+}
+
... | May as well fully sort this struct declaration now, same for `migrationFromInternal` below |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -0,0 +1,1118 @@
+package riverdrivertest
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "slices"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/require"
+
+ "github.com/riverqueue/river/internal/notifier"
+ "github.com/riverqueue/river/internal/rivercommon"
+ "github.com/riverqueue/river/interna... | Are these still meant to be empty? same comment for the other empty ones in here |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -1355,57 +1360,70 @@ func Test_Client_JobGet(t *testing.T) {
func Test_Client_JobList(t *testing.T) {
t.Parallel()
- var (
- ctx = context.Background()
- queries = dbsqlc.New()
- )
-
- type insertJobParams struct {
- AttemptedAt *time.Time
- FinalizedAt *time.Time
- Kind string
- Metadata []... | heh, this linter can get pretty annoying in tests. |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -1355,57 +1360,70 @@ func Test_Client_JobGet(t *testing.T) {
func Test_Client_JobList(t *testing.T) {
t.Parallel()
- var (
- ctx = context.Background()
- queries = dbsqlc.New()
- )
-
- type insertJobParams struct {
- AttemptedAt *time.Time
- FinalizedAt *time.Time
- Kind string
- Metadata []... | Thanks for adding this and fixing the issue :pray: |
river | github_2023 | go | 212 | riverqueue | bgentry | @@ -0,0 +1,1731 @@
+package riverdrivertest
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "slices"
+ "sort"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/require"
+
+ "github.com/riverqueue/river/internal/notifier"
+ "github.com/riverqueue/river/internal/rivercommon"
+ "github.com/riverqueue/river/interna... | realized from some of our other tests that we can just use 0 here and have no possibility of a flaky test ever
```suggestion
job, err := exec.JobGetByID(ctx, 0)
``` |
river | github_2023 | go | 222 | riverqueue | bgentry | @@ -79,25 +83,52 @@ func (d *DebouncedChan) nonBlockingSendOnC() {
}
}
-func (d *DebouncedChan) waitForTimer() {
+// Waits for the timer to be fired, and loops as long as Call invocations comes | ```suggestion
// Waits for the timer to be fired, and loops as long as Call invocations come
``` |
river | github_2023 | go | 221 | riverqueue | bgentry | @@ -77,3 +80,63 @@ func TestDebouncedChan_OnlyBuffersOneEvent(t *testing.T) {
case <-time.After(20 * time.Millisecond):
}
}
+
+func TestDebouncedChan_ContinuousOperation(t *testing.T) {
+ t.Parallel()
+
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ defer cancel()
+
+ const (
+ cooldo... | Nope, doesn't sound intentional at all. I think the purpose was for it to be a leading edge debounce algorithm (fire immediately, then do not fire again until (a) another signal comes in, and (b) at least `cooldown` has elapsed). |
river | github_2023 | go | 221 | riverqueue | bgentry | @@ -11,45 +11,66 @@ import (
// subsequent calls are delayed until the cooldown period has elapsed and are
// also coalesced into a single call.
type DebouncedChan struct {
- done <-chan struct{}
- c chan struct{}
- cooldown time.Duration
-
- mu sync.Mutex
- timer *time.Ti... | Do you want to preserve the traditional mutex organization where its declaration precedes all the things that it protects? I think it happens to actually be alphabetical here, but maybe we should keep the line gap and add a comment about `// protects the following` or w/e |
river | github_2023 | go | 221 | riverqueue | bgentry | @@ -11,45 +11,66 @@ import (
// subsequent calls are delayed until the cooldown period has elapsed and are
// also coalesced into a single call.
type DebouncedChan struct {
- done <-chan struct{}
- c chan struct{}
- cooldown time.Duration
-
- mu sync.Mutex
- timer *time.Ti... | Yeah, definitely doesn't sound like what I intended here. I wanted it to be leading edge, but if no other calls come in after the initial one nothing should happen, it should just be ready to fire again immediately on the next one.
However if a 2nd call comes in immediately after the 1st one, my thought was that we ... |
river | github_2023 | others | 220 | riverqueue | bgentry | @@ -7,12 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
-## [0.0.21] - 2024-02-19
+## [0.0.22] - 2024-02-19
### Fixed
- Brings in another leadership election fix similar to #217 in which a TTL equal to the elector's run interval plus a configured TTL... | I swear, we're gonna need a CI check for this 😆 |
river | github_2023 | go | 206 | riverqueue | brandur | @@ -101,6 +101,15 @@ type Config struct {
// Defaults to 1 second.
FetchPollInterval time.Duration
+ // ID is the unique identifier for this client. If not set, a random ULID will | What do you think about saying "random identifier" instead of "random ULID" here?
I'm kind of thinking that we shouldn't commit to the ULID algorithm specifically — it'd be nice to get rid of that dependency, and also I think a more human friendly combination of say host name plus start time might be a better defaul... |
river | github_2023 | others | 201 | riverqueue | bgentry | @@ -7,9 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [0.0.20] - 2024-02-14
+
### Fixed
-- Fix a leadership re-election query bug that would cause past leaders to think they were continuing to win elections. [PR #199].
+- Fix a leadership re-electi... | Doh; thanks |
river | github_2023 | others | 192 | riverqueue | brandur | @@ -18,9 +18,10 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
- postgres-version: [16, 15, 14]
go-version:
+ - "1.22"
- "1.21"
+ postgres-version: [16, 15, 14] | WFM. |
river | github_2023 | others | 192 | riverqueue | brandur | @@ -2,6 +2,8 @@ module github.com/riverqueue/river/cmd/river
go 1.21.4 | I think it's okay. One thing I've noticed is that to pick up a toolchain from a version, you need to have the patch version in there. i.e. `go 1.22` wont mind 1.22, but `go 1.22.0` will. |
river | github_2023 | others | 192 | riverqueue | brandur | @@ -2,6 +2,8 @@ module github.com/riverqueue/river/cmd/river
go 1.21.4
+toolchain go1.21.6 | Can we take `toolchain` out? Go should be able to pick it up from the version above. |
river | github_2023 | go | 192 | riverqueue | brandur | @@ -12,7 +12,7 @@ import (
const sampleGoMod = `module github.com/riverqueue/river
-go 1.21.4 | Won't matter as far as the test is concerned. |
river | github_2023 | go | 186 | riverqueue | brandur | @@ -1310,6 +1308,50 @@ func Test_Client_InsertManyTx(t *testing.T) {
})
}
+func Test_Client_JobGet(t *testing.T) {
+ t.Parallel()
+
+ ctx := context.Background()
+
+ type testBundle struct{}
+
+ setup := func(t *testing.T) (*Client[pgx.Tx], *testBundle) {
+ t.Helper()
+
+ config := newTestConfig(t, nil)
+ clien... | Hah, very unlikely, but small chance this fails locally because our test DB sequences don't get reset between runs. Probably will never happen, but I guess zero might be a slighter safer alternative. |
river | github_2023 | others | 184 | riverqueue | brandur | @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Changed
+
+- Validate queue name on job insertion. Allow queue names with hyphen separators in addition to underscore. [PR #184](https://github.com/riverqueue/rive/pull/184). | Typo here: "/rive/" |
river | github_2023 | go | 179 | riverqueue | bgentry | @@ -135,18 +136,7 @@ func (n *Notifier) getConnAndRun(ctx context.Context) {
conn, err := n.establishConn(ctx)
if err != nil {
- if errors.Is(err, context.Canceled) { | Hmm, hard to tell without digging into the code, but maybe it's possible pgx doesn't surface this source error correctly? `establishConn` is a simple method that just returns the result of `pgx.ConnectConfig` |
river | github_2023 | others | 117 | riverqueue | brandur | @@ -242,7 +242,7 @@ jobs:
- name: Setup sqlc
uses: sqlc-dev/setup-sqlc@v4
with:
- sqlc-version: "1.22.0"
+ sqlc-version: "1.24.0" | Maybe do a rebase here since I think the sqlc upgrade went through in a separate PR.
It might make sense to do these separately anyway, just so they go through quickly (small change so easy to review + merge) and don't end up interfering in multiple places.
FWIW, I don't usually upgrade to every new sqlc version ... |
river | github_2023 | go | 117 | riverqueue | brandur | @@ -1188,3 +1188,76 @@ func validateQueueName(queueName string) error {
}
return nil
}
+
+// JobList returns a paginated list of jobs matching the provided filters. The
+// provided context is used for the underlying Postgres query and can be used to
+// cancel the operation or apply a timeout.
+//
+// params := r... | So this error actually predates the `database/sql` driver slight. What it's trying to protect against is a case where you initiated a driver with a `nil` pool, but are trying to call a function that needs a pool. You might do this for example in a test case where you're only using test transactions:
https://riverque... |
river | github_2023 | go | 117 | riverqueue | brandur | @@ -1188,3 +1188,76 @@ func validateQueueName(queueName string) error {
}
return nil
}
+
+// JobList returns a paginated list of jobs matching the provided filters. The
+// provided context is used for the underlying Postgres query and can be used to
+// cancel the operation or apply a timeout.
+//
+// params := r... | This comment/example is still the original one for `InsertManyTx`. |
river | github_2023 | go | 117 | riverqueue | brandur | @@ -71,6 +72,29 @@ type JobInsertResult struct {
UniqueSkippedAsDuplicate bool
}
+type SortOrder int
+
+const (
+ SortOrderUnspecified SortOrder = iota
+ SortOrderAsc
+ SortOrderDesc
+)
+
+type JobListOrderBy struct {
+ Expr string
+ Order SortOrder
+}
+
+type JobListParams struct {
+ Conditions string | Just checking here: conditions are meant to be strictly stay an internal construct right? Just wondering if we have to do anything about making sure that SQL injections aren't possible. |
river | github_2023 | go | 117 | riverqueue | brandur | @@ -0,0 +1,271 @@
+package river
+
+import (
+ "encoding/base64"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "strings"
+ "time"
+
+ "github.com/riverqueue/river/internal/dbadapter"
+ "github.com/riverqueue/river/rivertype"
+)
+
+// JobListPaginationCursor is used to specify a starting point for a paginated
+// job list quer... | Just want to make sure I'm following: what's the purpose of this function? Is the idea here that it allows the cursor to be saved to JSON or otherwise persisted? Is that expected to be a feature that people want? |
river | github_2023 | go | 117 | riverqueue | brandur | @@ -0,0 +1,271 @@
+package river
+
+import (
+ "encoding/base64"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "strings"
+ "time"
+
+ "github.com/riverqueue/river/internal/dbadapter"
+ "github.com/riverqueue/river/rivertype"
+)
+
+// JobListPaginationCursor is used to specify a starting point for a paginated
+// job list quer... | Shed color, but IMO `JobListCursor` might be an adequate name for this that's a little less of a mouthful. IMO use of "cursor" implies pagination. |
river | github_2023 | go | 117 | riverqueue | brandur | @@ -0,0 +1,118 @@
+package dbsqlc | So I think my main (big) nit is mostly that this should live somewhere besides `dbsqlc` — I think that it's a little too confusing that this code _looks_ like it's generated, but it's not generated, and that `dbsqlc` shares a mix of generated and non-generated code. IMO, we should put it somewhere else even if it looks... |
river | github_2023 | go | 117 | riverqueue | brandur | @@ -1197,3 +1197,58 @@ func validateQueueName(queueName string) error {
}
return nil
}
+
+// JobList returns a paginated list of jobs matching the provided filters. The
+// provided context is used for the underlying Postgres query and can be used to
+// cancel the operation or apply a timeout.
+//
+// params := r... | I don't think that this syntax is valid is it? Go would want parenthesis around it at minimum like:
```
(river.JobListParams{}).WithLimit(10)...
```
It might be best to use the `NewJobListParams()` to construct it since we have that anyway. |
river | github_2023 | go | 117 | riverqueue | brandur | @@ -1197,3 +1197,58 @@ func validateQueueName(queueName string) error {
}
return nil
}
+
+// JobList returns a paginated list of jobs matching the provided filters. The
+// provided context is used for the underlying Postgres query and can be used to
+// cancel the operation or apply a timeout.
+//
+// params := r... | Same comment here. |
river | github_2023 | go | 117 | riverqueue | brandur | @@ -0,0 +1,130 @@
+package db | Ugh sorry for the churn, but could we call this something a little less generic so that tab complete works better? Maybe `dblist` until such a time that we want to put something else besides listing in the package. |
river | github_2023 | go | 117 | riverqueue | brandur | @@ -0,0 +1,288 @@
+package river
+
+import (
+ "encoding/base64"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "strings"
+ "time"
+
+ "github.com/riverqueue/river/internal/dbadapter"
+ "github.com/riverqueue/river/rivertype"
+)
+
+// JobListCursor is used to specify a starting point for a paginated
+// job list query.
+type J... | Are you sure about this one? Wouldn't it be better just to have an option for each timestamp field that you'd specify explicitly for what to sort on?
Currently, you have to read source code to understand what this will order by, and even if it were to be documented, it might be faster/easier to have users explicitly... |
river | github_2023 | go | 141 | riverqueue | brandur | @@ -935,6 +935,46 @@ func (c *Client[TTx]) runProducers(fetchNewWorkCtx, workCtx context.Context) {
}
}
+// Cancel cancels the job with the given ID. If possible, the job is cancelled
+// immediately and will not be retried. The provided context is used for the
+// underlying Postgres update and can be used to can... | IMO: if the job was about to be completed, just let that happen without the cancellation superseding it. However, if a job that was cancelled were to be set as retryable with the possibility of running again, that definitely seems wrong and should be fixed. |
river | github_2023 | go | 141 | riverqueue | brandur | @@ -274,6 +274,94 @@ func Test_Client(t *testing.T) {
require.WithinDuration(t, time.Now().Add(15*time.Minute), updatedJob.ScheduledAt, 2*time.Second)
})
+ t.Run("CancelRunningJob", func(t *testing.T) {
+ t.Parallel()
+
+ client, bundle := setup(t)
+
+ jobStartedChan := make(chan int64)
+
+ type JobArgs stru... | Hmm, I definitely would've leaned toward returning an error on a job that doesn't exist at all. The trouble is that it's quite easy in Go to pass the wrong value since all types are only "moderately strong".
e.g. You might be holding an `int64` that you think is a job ID, but is actually the primary ID of a differen... |
river | github_2023 | go | 141 | riverqueue | brandur | @@ -146,10 +146,15 @@ func (s *Rescuer) Start(ctx context.Context) error {
}
type rescuerRunOnceResult struct {
+ NumJobsCancelled int64
NumJobsDiscarded int64
NumJobsRetried int64
}
+type metadataWithCancelledByQuery struct {
+ CancelledByQuery bool `json:"cancelled_by_query"` | What do you mean exactly by "cancelled by query"? Does that just mean that it was cancelled and cancellation happens by a query so that it was cancelled by a query? |
river | github_2023 | go | 141 | riverqueue | brandur | @@ -150,12 +155,47 @@ func (p *producer) Run(fetchCtx, workCtx context.Context, statusFunc producerSta
// TODO: fetcher should have some jitter in it to avoid stampeding issues.
fetchLimiter := chanutil.NewDebouncedChan(fetchCtx, p.config.FetchCooldown)
+ handleJobControlNotification := func(topic notifier.Notifi... | OOC, are there any other actions you were expecting to come in? |
river | github_2023 | go | 141 | riverqueue | brandur | @@ -935,6 +935,90 @@ func (c *Client[TTx]) runProducers(fetchNewWorkCtx, workCtx context.Context) {
}
}
+// Cancel cancels the job with the given ID. If possible, the job is cancelled
+// immediately and will not be retried. The provided context is used for the
+// underlying Postgres update and can be used to can... | I kinda would've leaned toward having this return a job row representing the updated job for purposes of logging and additional checking. Thoughts?
A side benefit would be that it'd also allow you to disambiguate between the different edge conditions too. i.e. If the job was completed before it was cancelled, you co... |
river | github_2023 | go | 141 | riverqueue | brandur | @@ -274,6 +274,130 @@ func Test_Client(t *testing.T) {
require.WithinDuration(t, time.Now().Add(15*time.Minute), updatedJob.ScheduledAt, 2*time.Second)
})
+ // This helper is used to test cancelling a job both _in_ a transaction and
+ // _outside of_ a transaction. The exact same test logic applies to each case,... | > It makes me wonder if there's a more systemic issue here; should we be waiting for some components to come up before returning from `Start()`? Or should our `startClient` test helper always be waiting for the client to become healthy before returning?
Yeah, good question. I kind of suspect that ... yes, a `Start` ... |
river | github_2023 | go | 145 | riverqueue | brandur | @@ -0,0 +1,31 @@
+package river
+
+import (
+ "context"
+ "testing"
+
+ "github.com/jackc/pgx/v5"
+ "github.com/stretchr/testify/require"
+)
+
+func TestClientFromContext(t *testing.T) {
+ t.Parallel()
+
+ ctx := context.Background()
+ client := &Client[pgx.Tx]{}
+ ctx = withClient(ctx, client)
+
+ require.Equal(t, cli... | What do you think about switching to the use of `require.PanicsWithError` here? Just makes sure we for sure got the right panic and didn't trigger some other unexpected one by accident. |
river | github_2023 | go | 140 | riverqueue | brandur | @@ -135,7 +137,7 @@ func (n *Notifier) getConnAndRun(ctx context.Context) {
if errors.Is(err, context.Canceled) {
return
}
- log.Printf("error establishing connection from pool: %v", err)
+ slog.Error("error establishing connection from pool", "err", err) | I think this invocation and subsequent ones should be using the logger instance set above right? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.