jdellitt

jdellitt

Is it possible to pause a Workflow then continue it at a later time? For example, we’d like to start a Workflow with several Jobs, but want to put it into a suspended/paused state until some external event occurs (like a webhook), which would satisfy the dependency and resume the rest of the workflow. Been looking through the docs, and haven’t seen anything, so just wanting to rule out whether or not it’s possible. Thanks!

Showing Posts 1 to 6

cevado

cevado

Doesn’t appeding jobs to a workflow solve your issue?

You can create a workflow with all the jobs that doesn’t rely on the webhook.
When the webhook happens, you can append the jobs that depend on the webhook and include their dependency on other jobs.
This way you never need to worry about the “state” of the jobs in that workflow, Oban takes care of the dependencies after you append the new jobs.

jdellitt

jdellitt OP

Thanks @cevado, I do think that could work, but I was hoping to be able to define the whole Workflow up front (in a single place) as opposed to having that logic in two different places.

It seems like we may need to have a job in the middle that essentially checks for a condition and snoozes itself itself if that condition hasn’t been fulfilled.

cevado

cevado

you can make the code that append the jobs as a public function in the workflow module. this way you keep all the data about the workflow in the workflow module without needing to create a job that starves the queue/workers without a good reason.
you could even use the meta option of a job to add some internal identifiers that makes it easier to find the workflow when the webhook happens.

bkilshaw

bkilshaw

@jdellitt Did you ever figure this out by any chance?

jdellitt

jdellitt OP

No, unfortunately. I think we ended up going in a different direction altogether.

sorentwo

sorentwo

Oban Core Team

As alluded earlier in this thread, the way we usually suggest doing this is to have the job you’d like to pause snooze itself in a loop, with a limit to prevent unbounded retries. Here’s an example:

defmodule MyApp.PausedWorker do
  use Oban.Pro.Worker

  @impl Oban.Pro.Worker
  def process(job) do
    if some_external_event(job.args) do
      # do something here
    else
      {:snooze, 60}
    end
  end
end

You can optionally use unique and replace to upsert the snoozing job to run immediately, but it requires carefully setting the workflow_id:

  use Oban.Pro.Worker,
    unique: [meta: [:workflow_id, :name]],
    replace: [scheduled: [:scheduled_at]]

This question comes up rather frequently though, and a proper Oban.Pro.Workflow.pause/1 and Oban.Pro.Workflow.resume/1 seem warranted :thinking:

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews