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

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
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
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

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement