I’ve just recently added a new worker for my supervision tree and this worker on init does a DB lookup to load up some data. However that data does not exist until seeds.exs is ran. Previously I had no such dependency and my mix aliases worked fine.
["ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
"test": ["ecto.drop --quiet", "ecto.create --quiet", "ecto.migrate", "run priv/repo/seeds.exs", "test"]]
Is there some way I can get around this issue?
If I understand you correctly, your problem is that when you try to run any mix task, you get an error on your worker because your db is not seeded, and you can’t run your seeds for the same reason. Am I right?
ok so… I think you are doing something wrong. First of all, you are making your application dependent on external input source - the database. Which generally is bad but you make it worse by making application startup dependent on the external input - database state.
Have a look at what Phoenix is doing on it’s own: it starts the application no matter if the database connection is established properly or not. Yes, it will crash. But it will also retry reconnect every few seconds and if it does connect - it’ll start working as expected.
This is the pattern you can employ. If can’t load the state, fail. Retry after a few seconds.