Does `Oban.cancel_job/2` stop a running job if called from a rolled-back transaction?

If I call Oban.cancel_job/2 in a transaction, but the transaction is rolled back, will the job be cancelled?

I’m guessing that the db change to mark it cancelled would be rolled back, but I wasn’t sure if there a signal to kill the running job which would have already gone out.

You’re correct, the db change to mark it cancelled will be rolled back but the signal to kill the job may escape and kill any running jobs. It depends which notifier you’re using:

  • The Postgres notifier runs queries in the same transaction and it won’t emit any notifications when the transaction rolls back.
  • The PG notifier, or others, aren’t constrained by the transaction and may still kill the running job processes.

How can I check which notifier I’m using? Also, if the signal escaped and killed running jobs but the job status were rolled back, would it be picked up to run again?

It would be configured with :notifier, but if you haven’t configured anything, then the default is Oban.Notifiers.Postgres.

It would be left in the cancelled state. You’d have to manually retry it for it to run again.

OK, cool, in Oban.config() I see the notifier is Oban.Notifiers.Postgres.

The Postgres notifier runs queries in the same transaction and it won’t emit any notifications when the transaction rolls back.

Seems like a good reason to pick this notifier.

Thanks for the answers!

1 Like