sezaru
Why before_process is called twice if I cancel a running job?
I have a hook that implements before_process/1 and use it to log and pub_sub.
I noticed that, if I have a job currently in executing state, if I call Oban.cancel_job for it, before_process/1 will be called again before after_process(:cancel, …) is called.
Why is that?
This creates some issues to my case since I’m using this hook to send pub_sub messages, meaning that I end up sending a “wrong” executing message event (I send it if before_process/1 is called).
Btw, this seems to only happen using before_process/1, using telemetry [:oban, :job, :start] work fine.
Most Liked
sorentwo
This is by design and intentional. The cancel event is handled by a different process from the job. When the hook fires in a new process, there isn’t any stored/prepared job data, so before_process/1 is called again to reconstruct the job state before calling after_process/3 hooks.
This is done to ensure hooks have consistent job state, including any potential pre-processing that was done in before_process/1. The :start telemetry isn’t fired before cancellation, which is why it works the way you expect.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









