Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron tasks quantum elixir

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?

like image 305
Lety Cruz Avatar asked Jul 17 '26 06:07

Lety Cruz


1 Answers

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}
]
like image 158
Igor Drozdov Avatar answered Jul 18 '26 21:07

Igor Drozdov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!