riverqueue / river

Fast and reliable background jobs in Go
https://riverqueue.com
Mozilla Public License 2.0
3.34k stars 89 forks source link

`FinalizedAt` struct field is not set on `Job` for cancelled events #515

Open allancalix opened 1 month ago

allancalix commented 1 month ago

I'm subscribing to terminal job states:

    ch, cancel := rc.Subscribe(
        river.EventKindJobFailed,
        river.EventKindJobCancelled,
        river.EventKindJobCompleted)

And I noticed that the FinalizedAt struct field for Job is nil when the job is cancelled. This is confusing because other parts of the code seem to suggest that Finalized includes cancelled jobs so I would expect it to be set.

https://github.com/riverqueue/riverui/blob/93b4f537a1b64382ac359c42c8730255e9a9f446/ui/src/components/JobList.tsx#L174

bgentry commented 1 month ago

Can you confirm which mechanism you are using to cancel the job?

allancalix commented 1 month ago

I used the button in the UI in RiverUI, I'm assuming that calls JobCancel but I haven't checked. I did receive the event in the channel but got a nil pointer exception.

bgentry commented 1 month ago

Thanks! This must be a scenario where the job is running on a remote node and gets cancelled, but for some reason doesn’t emit the fully updated job state.

allancalix commented 1 month ago

I made a small program to replicate this issue but got a seemingly different issue, despite successfully canceling jobs I never get any events on my listener.

https://github.com/riverqueue/river/compare/master...allancalix:river:bug-cancel-sub-events?expand=1