bartblast

bartblast

Creator of Hologram

What is the bullet-proof way to get notified when any module in a Phoenix application gets recompiled?

I’m working on a bullet-proof live reload mechanism in Hologram, and I need a reliable way to be notified when any module in a Phoenix application gets recompiled and its .beam file gets updated.

From my research, I’ve discovered that there may be a few ways to approach this:

  1. Watching for .beam file changes - Set up a file system watcher to monitor changes to .beam files
  2. Hook into compilation tracers - Use Elixir’s compilation tracers somehow

What do you recommend? Is there another, more reliable approach that I’m missing?

I’m looking for a solution that’s as robust as possible, with minimal chances of missing any module recompilations, even in edge cases. Importantly, I want a mechanism that is not dependent on any Phoenix-related internals, just a pure Elixir way of doing this.

Thanks for your insights!

Most Liked

garrison

garrison

For my styled components library I used a Mix compiler to hook the compilation and then regenerate the compiled CSS from all of the modules. I didn’t do any checking of which modules were recompiled or anything, though. Figured I could do some diffing down the line if needed but I’ve yet to run into any performance problems. I think I stole most of the approach from Surface, which did roughly the same thing :slight_smile:

Looking at those docs now I see they’ve added some new stuff (related to the LSP work, I believe). I’ll have to look into that!

jstimps

jstimps

Is this what you’re looking for?

jstimps

jstimps

I meant to link :beam_lib.cmp_dirs/2 directly. I guess the Discourse magic didn’t pull that into the preview.

In any case, cmp_dirs will tell you which beams have differing code between two dirs. For example you can compare a release dir on the system with a release dir in a fresh clone to decide which modules have changed. I have used this in the past to do targeted reloads of specific modules in running production systems, without a restart and without relup. (Of course you have to know a priori that the module you’re loading is safe, and does not change any assumptions about runtime state)

I realize it’s not exactly what you’re looking for but maybe a piece of the puzzle.

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
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
chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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
albydarned
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

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
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
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement