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
kszambelanczyk
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
RemyXRenard
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
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
samoloth
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
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews