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, []},
6 Replies
🤔 not sure TBH
Solution
Its not an Ash specific thing though
You could make an alias for
seed
in your mix.exs fileIf 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.
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
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.