Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run code on application startup Phoenix Framework (Elixir)

Were would you put code which you want to run only when your application/api starts in vanilla Phoenix application? Let's say I want to make sure some mnesia tables are created or configure my logger backend. The other thing is runtime configuration. They mention it in documentation but it's not clear to me where one would define/change runtime configuration.

Endpoint.ex seems like a place where initial configuration is done but by looking at docs I can't find any callback that would allow me to run code only once at startup.

like image 284
Sebastian.Belczyk Avatar asked Jan 06 '16 00:01

Sebastian.Belczyk


1 Answers

Put it in the application callback module. It is usually the name of your application: lib/my_app/my_app.ex in the start/2 function. The 2nd line of the module should have use Application.

like image 137
Jason Harrelson Avatar answered Sep 21 '22 10:09

Jason Harrelson