AF
Ash Framework•4mo ago
Terris

Is there a way to detect running in "seed data" mode?

I added a custom GenServer that doesn't need to start when installing seed data using: mix run priv/repo/seeds.exs How might an Ash application know that it was invoked in a utility mode and not completely start itself? Code: https://github.com/dev-guy/geo/blob/28bdbb6c82a6d60927266527ae570046022b6e95/lib/geo/application.ex#L10 I added this line: {Geo.Resources.Country.CacheSupervisor, []},
Solution:
Its not an Ash specific thing though
Jump to solution
6 Replies
ZachDaniel
ZachDaniel•4mo ago
🤔 not sure TBH
Solution
ZachDaniel
ZachDaniel•4mo ago
Its not an Ash specific thing though
ZachDaniel
ZachDaniel•4mo ago
You could make an alias for seed in your mix.exs file
Terris
TerrisOP•4mo ago
If I was making say a JavaScript app, I would set an environment variable or perhaps a global variable or put it in config. The list of children in application.ex needs to change based on that. Now that I know I have to make it up myself, I will.
kernel
kernel•4mo ago
maybe check if like the endpoint has been started also? unless you start the endpoint while seeding? although that wouldn't really work if you are starting a non-web node i.e: as an oban worker
Terris
TerrisOP•4mo ago
That’s a good idea. I wonder if there are race conditions though. Instead I turned my supervisor into a dynamic supervisor. https://github.com/dev-guy/geo/blob/main/lib/geo/resources/country/cache.ex#L78
GitHub
geo/lib/geo/resources/country/cache.ex at main · dev-guy/geo
Contribute to dev-guy/geo development by creating an account on GitHub.

Did you find this page helpful?