ryanwinchester
Unique Workflows (no overlap per user)
I have an Oban Workflow that I want to limit so that only 1 Workflow will run for a user at a time, but not block for other users.
From the config it looks like I can do this per worker, but my workflow could have concurrent workers.
I don’t know if there is a way to do this with Oban config
help!
Any ideas?
Marked As Solved
sorenone
Yes! Indeed, there is. With Pro v1.6 you can set a global partition by workflow_name or some other unique attribute of that users workflow. (That’s really up to you). It’s more about concurrency and not uniqueness.
config :my_app, Oban,
queues: [
queue_name: [limit: 20, global_limit: [allowed: 1, partition: [meta: :workflow_name]]]
]
In this case, each node can run up to 20 jobs but only 1 of that particular workflow. It relies on you setting a distinct workflow name for each user.
Workflow.new(workflow_name: "some-workflow-#{user_id}")
Also Liked
julismz
Depending in the users amount, I would use a GenServer per user, saving in the state the jobs queue and a tick function wich take the first in the list, execute and update the state…
If you want to persist the state in case of crashes and you are not using a cluster, you can save the state in ETS… and load it again in the init callback.
If you are using a cluster, you can use Horde and recover the state with :continue flag.
I’m not sure if I would use Oban for this case…
ryanwinchester
sorenone
Last Post!
sorentwo
The context is stored by itself, it isn’t stored with every job. That means it’s impossible to partition by anything within the context because it’s simply not available on every workflow job.
Popular in Questions
Other popular topics
Latest Oban Threads
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









