quantum-elixir / quantum-core

:watch: Cron-like job scheduler for Elixir
https://hexdocs.pm/quantum/
Apache License 2.0
2.31k stars 148 forks source link

no function clause matching in Quantum.Normalizer.normalize_task/1 #533

Closed BryanJBryce closed 1 year ago

BryanJBryce commented 1 year ago

Sorry, this seems like something really basic, but I can't figure out what I'm doing wrong.

I've added Quantum to dependencies.

{:quantum, "~> 3.5"}

I've created a scheduler module:

defmodule Quest.Scheduler do
  use Quantum, otp_app: :quest
end

I've added that to the Supervisor children list:

children = [
   ...
      Quest.Scheduler,
   ...
    ]

And I've created a function to run with a schedule in the Schedule module (here are 3 of them to try to match the config one):

defmodule Quest.Scheduler do
  use Quantum, otp_app: :quest

  def do_it() do
    IO.puts("YOLO!!!")
  end

  def do_it([]) do
    IO.puts("ROLO!!!")
  end

  def do_it(_opts) do
    IO.puts("ZOLO!!!")
  end
end

Here is my cron job from config.exs

config :quest, Quest.Scheduler,
  jobs: [
    # Every minute
    {"* * * * *", {Quest.Scheduler, :do_it}, []}
  ]

I've also tried this:

config :quest, Quest.Scheduler,
  jobs: [
    # Every minute
    {"* * * * *", {Quest.Scheduler, :do_it}}
  ]

But get this error saying there is no function that matches:

(Mix) Could not start application quest: Quest.Application.start(:normal, []) returned an error: shutdown: failed to start child: Quest.Scheduler (EXIT) an exception was raised: ** (FunctionClauseError) no function clause matching in Quantum.Normalizer.normalize_task/1 (quantum 3.5.0) lib/quantum/normalizer.ex:95: Quantum.Normalizer.normalize_task({Quest.Scheduler, :do_it})

DimitrijeDimitrijevic commented 1 year ago

@BryanJBryce You are missing the closing curly braces in the first example. in the second you are missing arguments list.