tcoopman
So I have the following use case.
I have some code / modules that I want to run different versions of.
Let’s say I have a user, when they sign up - they interact with some code v0.
I now want to deploy new changes to the that code, but this first user should still interact with the code of v0. Another user with v1 and maybe some other on v2.
At some point in time the user could decide to update to v1 or v2, but it’s their decision.
I was thinking, if I could do something like:
Module.create(ModuleVersionX, module_contents, ...)
bytecode = capture_bytecode_of(ModuleVersionX)
save_bytecode_to database
// later
bytecode = capture_bytecode_from_db()
reload_module(bytecode)
My specific questions:
- how do I specify
module_contentsbased on an existing compiled module? - I think I can use
@after_compileto capture the bytecode of this new module? If I’m able to add this@after_compilehook in themodule_contents - I’m not sure how to load the bytecode again from the database.
- What are the catches of an approach like this?
I found the following topic that might be interesting, but the link in there doesn’t work anymore: Any ideas on how to generate compile-time module based on other modules?
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
What’s the issue in simply keeping version field for each user and just have all versions of the module in your codebase? And then just use
user.code_versionin acasestatement and dispatch to the right module + function?tcoopman
I’m not actually keeping track of versions manually. Most (but not all) of the code of the module is just text/markdown and changes often.
And multiple people can make changes to it.
So that would mean I need to keep track of all versions manually. I don’t want to do that.
In the future I might take a similar approach of what I think beacon is doing (compiling the module from text saved in the database), but right now that would be a big change that I don’t want to do.
dimitarvp
I see. Indeed in this case it’s best to just save the compiled bytecode to the DB.
tcoopman
Yes, so my question is how to do that. Well not just saving, but then using it again etc…
axelson
I have only minimal experience with this but I think you’d use a function like
:code.get_object_code/1to get the binary representation of a module:code.load_binary/3. Although if you’re running on IEx then you could get the binary code directly from thedefmoduleresult:{:module, _mode, binary, _} = defmodule Bench do def run do 42 end endand useCode.eval_stringto start from a raw string:Also I’d recommend storing the source code representation alongside the compiled binary. That will likely be necessary for checking for abuse, and also if you upgrade your Elixir/Erlang version.
LostKobrakai
You need to enforce unique names and figure out how to make the correct one be called. This is also effectively a remote code execution attack vector, so you want to take good care of who is able to affect those modules.
If there’s no hard need for elixir you can consider luerl / lua (Lua — Lua v0.4.0) instead, which would allow you to retain the ability to code up logical parts, while being able to be fully sandboxed.
If this happens to be around templating then I’d suggest GitHub - edgurgel/solid: Liquid template engine in Elixir · GitHub, which would be even more focused.
hlx
If I’m not mistaken I think BeaconCMS does something similar?
tcoopman
yes, but they start from a string/code representation that they compile, and they overwrite the existing module.
I want to create a new module each time - and preferably not from
codebut from thebytestringThat’s not really an issue:
I don’t need a sandbox. I just need a way to version code at runtime.
The flow would look something like this:
I’m not looking for a perfect solution. Just something that works good enough.
tcoopman
:code.load_binaryseems to be a big part of the solution. Thanks:code.get_object_codedoesn’t seem to work for dynamically defined modules - at least in iex. It does work forBut that doesn’t matter that much, because I get bytecode back from
Module.create.I guess to use
Module.createthough, I’ll need to have the actual code available?tcoopman
I think I found something that can actually help me fix this.
It’s not exactly what I’m looking for but it gets me a lot closer I believe: The horus application
From the readme:
Found it here: Horus - extract an anonymous function as a standalone module - #7 by dumbbell - Libraries - Erlang Programming Language Forum - Erlang Forums