bartblast
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:
- Watching for
.beamfile changes - Set up a file system watcher to monitor changes to.beamfiles - 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
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 ![]()
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
Is this what you’re looking for?
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.
Popular in Questions
Other popular topics
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
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









