-
Notifications
You must be signed in to change notification settings - Fork 178
Job cancellation doesn't work in database/sql driver #630
Open
Description
Hi!
I am using the example SortWorker job with small adjustments to test longer-running jobs with cancellation but it does not seem to work.
const SortJobKind = "sort" type SortArgs struct { Strings []string `json:"strings"` } func (SortArgs) Kind() string { return SortJobKind } type SortWorker struct { river.WorkerDefaults[SortArgs] } func (w *SortWorker) Work(ctx context.Context, job *river.Job[SortArgs]) error { log.Printf("STARTING: %d", job.ID) select { case <-ctx.Done(): log.Printf("CANCELLED: %d", job.ID) return ctx.Err() case <-time.After(20 * time.Second): log.Printf("WILL DO: %d", job.ID) } items := job.Args.Strings sort.Strings(items) log.Printf("RESULT: %+v\n", items) return nil }
When the job appears in the User Interface (riverui), I click Cancel but the job keeps running. In the logs I eventually get from STARTING to WILL DO but never observe CANCELLED.
The only thing that indicates some attempt at cancellation is the metadata field on the job which states:
{
"cancel_attempted_at": "2024年10月02日T....."
}Am I doing something wrong or is there a potential bug?
I am running v0.12.1 and using riverdatabasesql.New, though the underlying connection is pgx, wrapped with opencensus tracing (ocsql).
Activity
Metadata
Metadata
Assignees
Labels
No labels