adammokan

adammokan

Question about `after_process/3` callback in a `Oban.Pro.Workers.Workflow`

I’ve used the after_process/3 callback a number of times when implementing a Oban.Pro.Worker and it tends to work great for handling any cleanup or updating something in the database based on the job status.

I have a situation today where I’m implementing a Oban.Pro.Workers.Workflow with up to 3 dynamic child stages appended during execution and I realized I want to have a final callback that allows me to update a supporting record in the DB when the entire workflow completes. Reached for the after_process callback and instinctively added that to my first workflow stage, but (logically in hindsight) it fires right when that first stage completes rather than the entire workflow itself.

My primary question here is if I am missing something on how to handle this via a callback when using workflows? Or is the answer to append that final step I hoped to handle in the callback as a child of the workflow as its own job or is it recommended to attach that callback to the final stage of my workflow?

I think what makes this a bit confusing is that we do have a workflow-centric callback in the form of after_cancelled/4. So it seems like we should have some way to do the same for workflows that were not cancelled?

Appreciate any insight on this!

Update: I did just realize after_cancelled/4 is brand new as of last week. So maybe a similar approach for success cases is in the works :person_shrugging:

Marked As Solved

sorentwo

sorentwo

Oban Core Team

You’re not missing anything—appending a final job as the last step or adding an after_process/3 callback to the final job in the workflow is the way to solve this. I’d suggest a final job over a callback because you’ll have all the niceties of a job (i.e. retries), and it’s more obvious if you look at the workflow as a whole.

That callback is brand new (as noted in your update), and it was added to handle a situation that was impossible before. Prior to after_cancelled/2, there wasn’t any way to react to downstream workflow jobs getting cancelled because they weren’t actually running.

This use-case comes up frequently and a first-class approach for “batch callback” functionality in workflows is in the works :slightly_smiling_face:

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
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New

Other popular topics Top

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
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
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31013 112
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
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
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
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement