# Running code on Phoenix start?

**URL:** <https://forum.elixirforum.com/t/running-code-on-phoenix-start/20346>\
**Category:** Questions\
**Tags:** cache, phoenix, restarting\
**Created:** [February 21, 2019, 8:32pm UTC](https://forum.elixirforum.com/t/running-code-on-phoenix-start/20346 "2019-02-21T20:32:58Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![fireproofsocks](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fireproofsocks/32/7669_2.png) [@fireproofsocks](https://forum.elixirforum.com/u/fireproofsocks)\
**Post date:** [March 26, 2019, 4:51pm UTC](https://forum.elixirforum.com/t/running-code-on-phoenix-start/20346/3 "2019-03-26T16:51:39Z")

</div>

I tried adding a child to the supervision tree which boiled down to this:

```elixir
defmodule MyApp.Application do
  alias MyApp.Contexts.MyContext
  use Application

  def start(_type, _args) do
    import Supervisor.Spec, warn: false
    
    children = [
      supervisor(MyApp.Repo, []),
      worker(Task, [&MyContext.warm_up_cache/0], restart: :temporary)
    ]
    
    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

```

That works, but blows up with errors when the database is down or being provisioned (which is obvious in retrospect). Instead, I think what I want in this case is a _blocking_ task: i.e. wait to start the rest of the app until this one thing is complete.

Does someone have a good example of how to do something like this? My example here is warming up the cache.

Thanks for any guidance!

---

_[View the full topic](https://forum.elixirforum.com/t/running-code-on-phoenix-start/20346)._
