Alex Antonov
Alex Antonov

Reputation: 15156

How could I disable some configs if I'm loading from IEx?

I have tons of quantum jobs that generates log trash inside my iex. From my phoenix app:

# config/dev.exs
config :quantum, MyApp,
  cron: [
    # Tons of jobs here
  ]

So, I want this part to be included in configs only from the phoenix.server, but not from IEx. How could I do that?

Upvotes: 1

Views: 196

Answers (2)

iloveitaly
iloveitaly

Reputation: 2155

I'm on elixir 1.15. In my case, IEx.started? returns false in the runtime.exs and prod.exs file. My assumption is this is because these files are executed before whatever state IEx.started? relies upon is updated.

In my case, the way to disable quantum in IEx on prod was to create .iex.exs file and remove the scheduler process:

Supervisor.terminate_child(App.Supervisor, App.Scheduler)
Supervisor.delete_child(App.Supervisor, App.Scheduler)

Upvotes: 0

Dogbert
Dogbert

Reputation: 222198

You can check if iex is running using IEx.started?/0. If you put this in unless and wrap the config call inside it, the config will only be added if iex is not running:

# config/dev.exs
unless IEx.started? do
  config :quantum, MyApp,
    cron: [
      # Tons of jobs here
    ]
end

Upvotes: 3

Related Questions