lessless
Ensuring per user workflow uniqueness
Hi,
Is there a way to ensure that only one workflow will be scheduled per user in a 3-hour window?
Unlike Unique Workflows (no overlap per user) - #4 by sorenone , this is an idempotency/uniqueness question.
I noted in Oban.Pro.Workflow — Oban Pro v1.6.12 that workflow_id must be unique, and tried to set it to “sync-account-transactions #{account.id}”, but that didn’t prevent insertion.
Best,
Yevhenii
Marked As Solved
sorentwo
Oban Core Team
Sure! The trick is to put a single job with uniqueness in front of the workflow creation. Here’s an example:
defmodule MyApp.Flow do
# The worker doesn't normally have unique enabled
use Oban.Pro.Worker
alias Oban.Pro.Workflow
# Gate the workflow behind a job that's unique by the user id
def invoke(user) do
%{user_id: user.id}
|> new(unique: [period: {3, :hours}])
|> Oban.insert()
end
@impl Oban.Pro.Worker
def process(job) do
user = MyApp.Repo.get(MyApp.User, job.args["user_id"])
# Build up the workflow within the invoked job. Using context and cascade purely as an example.
Workflow.new()
|> Workflow.put_context(%{user: user})
|> Workflow.add_cascade(:a, ...)
|> Workflow.add_cascade(:b, ...)
|> Workflow.add_cascade(:c, ...)
|> Oban.insert_all()
end
end
1
Last Post!
lessless
Popular in Questions
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Other popular topics
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
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
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
Hello everyone,
Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
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
- #api
- #forms
- #metaprogramming
- #security
- #hex









