Quantum Child Specification Error in Elixir Application

Hi,

versions:

  • {:quantum, "~> 3.5.3"}
  • elixir: "~> 1.14"

I’ve encountered an issue with integrating the Quantum scheduler into my Elixir application’s supervision tree. Despite following the documentation and ensuring that Quantum is correctly added as a child to the supervisor, I’m still facing an error related to the child_spec/1 function.

Here’s the error message I’m receiving:

Application featureflagservice exited: exited in: Featureflagservice.Application.start(:normal, [])
** (EXIT) an exception was raised:
    ** (ArgumentError) The module Quantum was given as a child to a supervisor
    but it does not implement child_spec/1.

This error persists even after specifying Quantum in the application’s supervision tree as follows:

children = [
  # ... other children ...
  {Quantum, [name: Featureflagservice.Scheduler]}
]

And here’s the relevant part of my config.exs where I define the Quantum jobs:

config :featureflagservice, Featureflagservice.Scheduler,
  jobs: [
    # Jobs configuration
    # Every 2 hours, set the feature flag to 1.0 for cartServiceFailure
    {"@every 2h", {Featureflagservice.FeatureFlags, :toggle_feature_flag, ["cartServiceFailure", 1.0]}},
    # Every 30 minutes, set the feature flag to 0.0 for cartServiceFailure
    {"@every 30m", {Featureflagservice.FeatureFlags, :toggle_feature_flag, ["cartServiceFailure", 0.0]}}
  ]

I’ve ensured that Quantum is included in my mix.exs dependencies and fetched with mix deps.get. My Elixir and OTP versions are compatible with the Quantum version I’m using.

Could anyone provide insights into what might be causing this issue or suggest a solution? Any help would be greatly appreciated.

Thank you!

Full error:

feature-flag-service exited with code 1
feature-flag-service     | 14:56:12.884 [info] Migrations already up
feature-flag-service     | 14:56:13.268 [notice] Application featureflagservice exited: exited in: Featureflagservice.Application.start(:normal, [])
feature-flag-service     |     ** (EXIT) an exception was raised:
feature-flag-service     |         ** (ArgumentError) The module Quantum was given as a child to a supervisor
feature-flag-service     | but it does not implement child_spec/1.
feature-flag-service     | 
feature-flag-service     | If you own the given module, please define a child_spec/1 function
feature-flag-service     | that receives an argument and returns a child specification as a map.
feature-flag-service     | For example:
feature-flag-service     | 
feature-flag-service     |     def child_spec(opts) do
feature-flag-service     |       %{
feature-flag-service     |         id: __MODULE__,
feature-flag-service     |         start: {__MODULE__, :start_link, [opts]},
feature-flag-service     |         type: :worker,
feature-flag-service     |         restart: :permanent,
feature-flag-service     |         shutdown: 500
feature-flag-service     |       }
feature-flag-service     |     end
feature-flag-service     | 
feature-flag-service     | Note that "use Agent", "use GenServer" and so on automatically define
feature-flag-service     | this function for you.
feature-flag-service     | 
feature-flag-service     | However, if you don't own the given module and it doesn't implement
feature-flag-service     | child_spec/1, instead of passing the module name directly as a supervisor
feature-flag-service     | child, you will have to pass a child specification as a map:
feature-flag-service     | 
feature-flag-service     |     %{
feature-flag-service     |       id: Quantum,
feature-flag-service     |       start: {Quantum, :start_link, [arg1, arg2]}
feature-flag-service     |     }
feature-flag-service     | 
feature-flag-service     | See the Supervisor documentation for more information.
feature-flag-service     | 
feature-flag-service     |             (elixir 1.14.3) lib/supervisor.ex:701: Supervisor.init_child/1
feature-flag-service     |             (elixir 1.14.3) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
feature-flag-service     |             (elixir 1.14.3) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
feature-flag-service     |             (elixir 1.14.3) lib/supervisor.ex:687: Supervisor.init/2
feature-flag-service     |             (elixir 1.14.3) lib/supervisor.ex:617: Supervisor.start_link/2
feature-flag-service     |             (kernel 7.3.1.5) application_master.erl:277: :application_master.start_it_old/4```

Which documentation specifically? Whatever it was, it appears to be outdated. The current docs recommend a different approach where you create a “scheduler” module that does use Quantum and add that to your application’s supervision tree.