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?
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}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With