lamxw2
Pausing Jobs Instead of Queue?
Hi there. I am currently working on migrating our current queue system from GenServers to Oban (Pro). I am implementing this in phases, so not all entities will be running in Oban yet, which means based on a condition, some entities use our existing queue, and the remainder get queued in Oban.
We want to prioritize the entities using our existing queue system, so the plan was to pause the relevant Oban queues when the current queue is not empty, then resume Oban queues when that queue is empty.
However, I have run into Ecto.StaleEntryError
Last message: {:notification, :signal, %{"action" => "pause", "ident" => "any", "queue" => <omitted>}}
Last message: {:notification, :signal, %{"action" => "resume", "ident" => "any", "queue" => <omitted>}}
I have tried:
- Using
Oban.check_queueand pause/resume based onqueue.pausedvalue, however that requires a db query call every time an entity is queued, which is not very efficient.StaleEntryErroroccurs - Adding a boolean field
oban_pausedto my GenServer states, this prevents a db query every time. However we have multiple GenServers that share a queue, so theoban_pausedboolean is inaccurate based on the queue. This also still has aStaleEntryErroron a specific GenServer that doesn’t share a queue, so it seems like our system is too quick and a race condition happens as well. - Wrapping
Oban.pause/resume_queuein atry catch, but this doesn’t work either.
The next solution I thought of doing was manually pausing (changing the state) Oban.Job instead of the queue itself, which I think would work out better especially for our GenServer states that share a queue, since we rate limit and partition our queues based on that. However, I don’t see a suitable state that can be used, aside from scheduled, but that would require setting a time for the Job, which isn’t suitable for our use case.
I am looking for an easy workaround, because we won’t need to resume/pause queues like this after our entire current system has been moved to Oban.
Any other suggestions are welcome!
Most Liked
sorentwo
The Ecto.StaleEntryError you’re getting is from a bug in DynamicQueues that was fixed in the rather recent Pro v1.5.0-rc.4.
Note that Oban.check_queue doesn’t query the database. It returns information directly from the queue’s producer process.
The easiest workaround is to upgrade to the latest RC (it’s stable, no known bugs at this point) and avoid the annoying StaleEntryError bug
.
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
- #performance








