sheharyarn
Update Oban Job's scheduled_at time
I have an Elixir app that uses Oban to schedule jobs at a time specified by users. For example, users can specify the date and time to send a certain email.
Oban works great at scheduling the job initially, and with other features like uniqueness, but I can’t find a sensible way to update the scheduled time of an existing job (when the user wants to change the time).
Currently, two approaches come to mind:
1. Cancel job and queue again
job =
Oban.Job
|> where(fragment("args->>'task_id'") == ^task_id)
|> where([j], j.state in ~w[available scheduled])
|> Repo.one()
Oban.cancel_job(TaskWorker, job.id)
job.args
|> TaskWorker.new(schedule_at: new_time)
|> Oban.insert()
2. Update job manually
Oban.Job
|> where(fragment("args->>'task_id'") == ^task_id)
|> where([j], j.state in ~w[available scheduled])
|> Repo.one()
|> Ecto.Changeset.cast(%{scheduled_at: new_time}, [:scheduled_at])
|> Repo.update()
But I worry that Oban might have its own hooks which do not get called when updating manually or if there’s a better way to do this.
Also posted on Stackoverflow:
Marked As Solved
sorentwo
Oban Core Team
Also Liked
sorentwo
Oban Core Team
As of a recent (and unreleased) PR, there is built in support for this exact situation:
4
Popular in Questions
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
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
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
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
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
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
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
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









