3

I want to execute a code every minute and I tried an attempt using the following code:

#your_app/mix.exs
defp deps do
    [{:quantum, ">= 1.9.1"},    
     #rest code
  end



#your_app/mix.exs
def application do
    [mod: {AppName, []},
     applications: [:quantum,
     #rest code         
   ]]
  end

#your_app/config/dev.exs
config :quantum, :your_app, cron: [
    # Every minute
    "* * * * *": fn -> IO.puts("Hello QUANTUM!") end
]

This is the one of the answers to this question How to run some code every few hours in Phoenix framework?

However, when I execute iex -S mix it doesn't show any message, neither an error message.

Do you know what the problem would be?

Lety Cruz
  • 133
  • 1
  • 16
  • Are you on quantum 2.0.0? Looks like they changed their API significantly in v2. See https://hexdocs.pm/quantum/migrate-v2.html and https://hexdocs.pm/quantum/readme.html. They have the updated instructions there. – Dogbert Aug 09 '17 at 05:57
  • Yes, I'am using quantum 2.0.0, I also tried what the documentation says but it's still not working. – Lety Cruz Aug 10 '17 at 00:23

1 Answers1

3

The answer that you referred must be outdated. According to the documentation you need to create your own scheduler:

defmodule YourApp.Scheduler do
  use Quantum.Scheduler, otp_app: :your_app
end

Start it as a worker in lib/your_app.ex

children = [
  supervisor(YourApp.Repo, []),
  supervisor(YourApp.Endpoint, []),
  ...
  worker(YourApp.Scheduler, [])
]

And configure in config/dev.exs using the following format:

config :test, YourApp.Scheduler, jobs: [
  # Every minute
  {"* * * * *", fn -> IO.puts("Hello QUANTUM!") end}
]
Igor Drozdov
  • 14,690
  • 5
  • 37
  • 53