dmitriid
Create a module in memory, refresh/reload on change
It’s one of those “if you try it, you can figure it out” questions. I’m just hoping someone has already done this before and has some quick tips or a link to look at ![]()
The meat of the question is: I have something in a file (data, or a custom DSL, or anything, really). Using this something, I want to create and compile an Elixir module and load it into the running application. When that something changes (let’s say, a file watcher tells me that contents have changed), I want to re-create/re-compile that module and reload it.
I know that I should start looking at Module.create/3. Perhaps there are other things I can/should look at and consider?
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
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
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
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
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
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
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
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
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
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 5 of 5 Posts
kokolegorille
You might use @external_resource attribute on a module…
If the external resource file change, the module will recompile.
03juan
You could try Code.eval_string/3 if you want to parse the changed “something” file from within Elixir to produce a string representation of the module def.
Alternatively Code.eval_file/2 if you dynamically write/update an
.exfile from your “something” file.mudasobwa
This is compilation-time dependency, which helps to mark a module as “recompilation needed” for the regular elixir compiler when say
mix compileis to be invoked next time. It has zero value here, unfortunately.Yes, kinda. There is a pitfall one should be aware of: the module recompilation is not instant.
I would spawn the process as gateway access to the module to be recompiled that both recompiles whatever is needed and its mailbox acts as a queue for both subsequent recompilations and all the interactions with this module. That way one can be sure that the module gets accessed if and only it’s available.
Please note, that
Module.create/3accepts an AST. If you want to load a regular.ex[s]file, useCode.eval_file/2as suggested by @03juan.kokolegorille
Oops, my bad… I did not catch it should be for runtime.
dmitriid
Good point/catch about the queue. Especially if I want this to be based on a custom DSL or custom data, compilation will definitely not be instant.