dcdourado

dcdourado

When a module attribute is based on the return of a function defined on another module, can we say we’ve a module dependency? Module A defines and exposes a module-attribute through a public function and Module B defines another module-attribute based on the return of that function.

This affirmation (module dependency) makes sense to me because module attributes are defined on compile time, and because of that Module B (which contains a module-attribute that depends on the definition of Module A) now has a dependency of Module A being before. Is this the correct concept?

Anyway, the real problem here is the redefinition of modules on this scenario. I’ve made a quick demo that shows that a redefinition on the module that possess the module-attribute won’t take any effect on the other module.

Is there a hook like @before_compile which can help me here? The main goal is to define some values and make Module A the single source of truth of these values, which will be used as guards, changeset validations and features based on this business-rule.

Showing Posts 1 to 8

OvermindDL1

OvermindDL1

So I cloned the demo, I ran mix deps.get && mix compile and then loaded it in iex via iex -S mix, I run:

iex(1)> {ModuleDependency.ModuleA.values, ModuleDependency.ModuleB.values}
{[:value_a, :value_b, :value_c], [:value_a, :value_b, :value_c]}

And they match, so then I edit the values in ModuleA by commenting the old values and uncommenting the commented new values, I then run this in that same iex session:

iex(2)> recompile                                                         
Compiling 2 files (.ex)
:ok
iex(3)> {ModuleDependency.ModuleA.values, ModuleDependency.ModuleB.values}
{[1, 2, 3], [1, 2, 3]}

And it worked fine here? You might need to give more details on what you are doing. Remember that module dependencies are handed by mix/compiler (pasting things in the REPL does not use mix/elixirc, calling recompile, which is just an import for IEx.Helpers.recompile/0 however does, mix/elixirc works on files, not interpreted code put in via the REPL in very short summary).

dcdourado

dcdourado OP

Thanks for the response @OvermindDL1!

On production level I can’t change the code and recompile it because of the difficulties of doing it on a running docker image and I’m afraid calling recompile command could harm a production-running application.

Given a scenario where a quick fix is required, pasting a module with changes on console may best than a full-deploy on terms of speed. Is this a legitimate worry? Should I be concerned about this?

OvermindDL1

OvermindDL1

Pasting code into the REPL will not perform any compiler-related cross-file work. The REPL is for interacting with a running system, not for compiling projects. ^.^

But what difficulties are you having with it in a docker container, I’ve had no issues here?

But still, when you’ve automated a full deploy with hot code swapping then it’s really really fast anyway (don’t even need to restart a docker container, hot code swapping is very nice!). :slight_smile:

dcdourado

dcdourado OP

My docker image basically copy project files, fetch deps, build and make release with Distillery.
I am not aware of how I could change the source code on the container and from this event the project updates the /bin application…

I will take further research on hot code swapping, thanks!

OvermindDL1

OvermindDL1

Yep! You can make a new release, copy it into the container (it doesn’t overwrite, it goes in as an actual release) then you ‘upgrade’ from one release to the other, which loads the new code, migrates data, keeps running old code in actors until they perform a new module call, etc… It works very well once set up if you want no downtime, it’s what we do here. :slight_smile:

al2o3cr

al2o3cr

TBH this sounds like a recipe for disaster when the infrastructure spins up a new instance using that image; how would it get the “fix”?

dcdourado

dcdourado OP

Exactly, it won’t. This is a problem I’m aware of

dcdourado

dcdourado OP

Seems great, thanks for the tip!

Since the infrastructure here is based on k8s, it will get a little tricky to change the deployment strategy of docker-image pushes on registry, but I can see the benefits! Definitely will take some time to explore this option :slight_smile:

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
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...
New
JesseHerrick
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
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews