BeacoHealthPublic

BeacoHealthPublic

I want to auto compile/reload/hotswap the Elixir server side code whenever a file changes. For example, reload the controller, or reload the app inside the business logic/contexts section. How do you setup the config.

Here is how I have setup the config in the dev.exs section inside the config folder:

config :discuss, DiscussWeb.Endpoint,
reloadable_compilers: [:gettext, :phoenix, :elixir],
reloadable_apps: [:ui, :backend]

of course, if I change the code inside one of the controllers, it doesn’t work. How do you do this?

Showing Posts 1 to 10

NobbZ

NobbZ

The hotcode reloader is meant for development only. It only watches source files in the project directory, nothing else.

In production there is usually no need to watch sources, as you usually do not replace single source files, but the application as a whole.

If though those files are some data files, then I’m not sure why you want to reload a controller…

Usually there are better means of communication inside the application or with external applications than the local file system.

BeacoHealthPublic

BeacoHealthPublic OP

Hi I mean in dev.

I’ve just discovered that the phoenix code reloader does work… it just doesn’t work when I edit the controller.ex files in vscode…

Have no idea why… It even happens when no plugins are installed.

Its as if vscode saves the file under some format which elixir doesn’t like.

If you wish to reproduce this, its easy. Download vscode, make a new elixir project. try editing some .ex file like UserController.ex, refresh the page, notice that the page doesn’t get updated.

NobbZ

NobbZ

So you want to use it for development? Okay, your intial post read as if you want to use the code reloader in production.

Since the code reloader works for me quite fine, and I do use VScode(ium), I have to ask what operating system you use and if you have installed the proper filesystem tools to make filewatches possible at all. Otherwise the reloader will fallback into a “polling” mode, which scans the filesystem only every few seconds and is inherently slow compared to proper watches.

Having said that, there are still files left the reloader refuses to trigger a recompilation on. IIRC the endpoint and the routes as well as changes at the mix.exs or config/*.exs wont trigger a reload, as the require a restart anyway.

Last but not least, newly added files won’t trigger a reload as well, only files that existed when you started the server.

BeacoHealthPublic

BeacoHealthPublic OP

so I am on ubuntu 18.04 and vscode version 1.35.1, I tested it by modifying the router.ex file. I tried both with ElixirLS plugin enabled and disabled, and I do have inotify-tools installed.

I tried it with atom editor and the atom editor works… not sure what specifically is going on with VScode, it has nothing to do with the plugins.

I also tried changing MIX_ENV=test then running the compile, as suggested by several posts, this did not solve the problem.

Lastly on my system, I have an issue with recompile. I think this recompile error is related to the above problem AND its easier to reproduce

so if you create a new project: mix new foo

Then open that project in vscode file → open → foo

Then inside the integrated terminal, do iex -S mix

then do recompile → answer is :noop (as expected because iex -S mix compiles your files)

BUT!

if you change something in an ex file in the lib folder(for example, inside foo.ex inside the hello world function, change :world to “hi there!”, then save it with vscode

THEN inside the integrated terminal do recompile

it shows :noop! when it should show :ok

This is definitely caused by vscode because if I perform the above steps in atom or in terminal(using gedit as the file editor) it show :ok instead of :noop.

NobbZ

NobbZ

When you run iex -S mix then afaik the reloader won’t be started (AFAIR not even the server), you need to run iex -S mix phx.server to actually start phoenix and related tools…

BeacoHealthPublic

BeacoHealthPublic OP

my mistake, I didn’t communicate what I was trying to say well enough.

I am talking about 2 issues I have. The first issue is the phoenix server does not auto reload the code. But I have a 2nd separate issue. This issue is, inside a normal project(not a phoenix project) if I try the recompile command it show :noop instead of :ok(it shows noop even when it should show ok. i.e. it shows noop even while ex files have been edited). I think the second issue is related to the first issue. I think the first issue is caused by the second issue. I think if the 2nd issue was resolved, the first issue would be resolved. Even though the 1st issue and the 2nd issue are completely separate, independent issues that I have.

NobbZ

NobbZ

I have never experienced such issues. Are you strictly sure that the code you edit and the iex session you start are in the same project?

lud

lud

Hello, I have a similar problem of code reloading : when I edit js or eex files, the reload works, but not when I edit a controller. Any idea ?

I am using Sublime Text and Mac OS

NobbZ

NobbZ

How does your live reload configuration looks like? per default it does only relead on static assets and templates.

lud

lud

That was it, sorry for the newbish question, I thought watching the controllers was a default (didn’t it use to ?) so I did not check the docs.

Thank you !

Does phoenix “know” that it must wait for the new code to be loaded before sending the page reload message ?

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
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
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
Onor.io
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
Trolleger
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
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
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
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

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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews