lcabrini

lcabrini

A few years ago a built a system in Go that I’m trying to rebuild as a part of learning more about Ash and Phoenix. This involved users being able to generate various reports relating to water bodies in West Africa. We got the data by talking to a remote web service. This was usually very slow and it could take quite a while to get a repsonse back. In addition, we were only supposed to allow a limited number of report requests to run at a time (a value that they admins could change). Once we got a reponse back we would pull out the relevant information from the JSON and send it to a report server which would generate a report and give us a link which we could pass on to the user. Do to issues with electricity and stuff, the pending jobs would have to be able to restart if something were to happen and the service needed to be restarted.

I’m interested in how to conceptually tackle this using Ash. I’m sure I could pretty much follow the procedure I did in Go, but it feels like Ash provides functionality that might be of use here. I’m looking at the state machine and/or possibly the reactor? I have really dug into these yet, but it “smells” like one or both of them might be useful in some way.

I’d like to know if there is some Ash-esque way of dealing with those requirements and what that would involve. The Go solution ended up working well enough, but the code was a bit of a nightmare both to maintain and to build upon.

Showing Posts 1 to 10

lud

lud

If you need to be able to restart because of electricity shutdown, you must have your jobs-to-do in database. In that case a simple solution is to use Oban.

Oban will let you control how much workers you will have in your queue.

Infortunately if the server shutdowns during execution of an Oban job, on restart Oban will believe that the job is still “executing” and will not restart it (except if you use Oban Pro). But if you have a single instance of your application running, that is easy: On start, check if there is any job with the “executing” state in database and set it to “available”. And only then start the Oban queue.

Not sure how Ash could help there though.

jimsynz

jimsynz

Ash Core Team

@lud is right - I feel like Oban is the way to go here. We have ash_oban to help ease the integration but it’s not a hard requirement.

Reactor is only really useful if you have a multi-step process that you want to orchestrate. You can run a reactor inside your Oban job if you decide to go that way.

Also look at ash_state_machine as it may be relevant.

lcabrini

lcabrini OP

Thank you for your response.

Thanks, will look into Oban.

Yeah, that is what I was doing in the Go version. I had a table with jobs and their state (waiting, in-progress, done).

Sure. That was a problem we faced in the original implementation as well. And we solved exactly that way: upon server start, reset all jobs that were marked in-progress.

lcabrini

lcabrini OP

Just reading up on Oban. Definitely is something I need to look into. Will also look at ash_oban to see what it does.

Oh, okay. I’ll be honest I just skimmed through the documentation quite quickly. Even if it is not the right thing for this particular project, it looks interesting and deserves some attention at some point.

In the original implementation, we used a field in the database table to store the current state of each job and then I transitioned between states. So yes, ash_state_machine does look interesting from that point of view, especially as I can define rules for which state transitions are allowed (if I read that right). Again, seems really useful, not just for this project but for many of the types of project I typically work on.

sorentwo

sorentwo

Oban Core Team

You don’t need Pro to rescue stuck jobs (orphans), that’s available with the standard Lifeline plugin. The difference with Pro is it isn’t as smart about restarts.

Side note—every persistent queue may either drop executing jobs silently (like Sidekiq), or you’ll have orphans that need to be dealt with. It’s a good thing!

lud

lud

Ah!

I hesitated to ping you here for this but I checked it before and a google search for “oban lifeline” returns this page for v2.9.1 stating that This plugin is available through Oban.Pro.

But in your link for 2.16.3 the mention is gone :slight_smile: Thanks for making it available!

lcabrini

lcabrini OP

That’s good to know. I live in a part of the world where unfortunately the price of pro might be out of reach for some of our clients. So I’ll have to live with what I get and try to work around it myself. I have a habit of personally donating to open source projects that I rely upon so will need to investigate the possibility of donating to the open source effort at least. For now, that is probably the best I can do.

lud

lud

the price of pro might be out of reach for some of our clients

Don’t worry, Oban free is already an excellent product :slight_smile:

jimsynz

jimsynz

Ash Core Team

Be careful with this approach if you plan on ever adding distribution or any kind of rolling deploys to the application. How can it tell that it’s starting clean or it’s starting while another instance is already running?

lcabrini

lcabrini OP

Good point, but is not a problem in this particular case. But I’ll keep that in mind.

— All posts loaded —

Where Next? Top

Trending in Questions Top

axelson
One of my LiveView view’s has a very heavy javascript dependency so I want to avoid loading it for every page on the site, while still us...
New
yasoob
Hi all! I know that quite a few people use Phoenix LiveView but it is hard to get a more up-to-date list of folks/companies using it. I ...
New
Hellowman
Hello everyone! I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++. Does anyone ...
New
yarrichar
I’m very new to Elixir, so sorry if this is a silly question: I am wondering what happens to the mailbox of a process when the machine i...
New
mandar1045
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
caioaao
Hey, I know this has been discussed ad nauseum, but I couldn’t find a definitive answer or at least some consensus around this, so let me...
New
Liam_or
I don’t suppose you can lazy load a library depending on runtime data? For example if it’s a certain user they can lazy load ‘library A’ ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
261 13183 112
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
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
charlenopires
Hi everyone :waving_hand: I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New
PJUllrich
On November 23, 2026, an unauthorized third party exploited a vulnerability in hex.pm (CVE-2026-129514, CVSS 10.0) that let them run comm...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews