ryanwinchester

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

sorenone

Oban Core Team

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

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

ryanwinchester

yeah workflow_name :sweat_smile:

sorenone

sorenone

Oban Core Team

We run it in production. It’s in rc for a while, at least a month. Totally up to you.

Last Post!

sorentwo

sorentwo

Oban Core Team

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.

Where Next?

Popular in Questions Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement