quantum-elixir / quantum-core

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

Issue with Phoenix code reloading? #575

Closed cjbottaro closed 4 months ago

cjbottaro commented 10 months ago

I frequently see this error in my logs:

[error] ** (UndefinedFunctionError) undefined function
    #Function<3.41462932/0 in :elixir_compiler_1>()
    (quantum 3.5.0) lib/quantum/executor.ex:98: anonymous fn/4 in Quantum.Executor.run/5
    (telemetry 1.2.1) /multiverse/elixir/deps/telemetry/src/telemetry.erl:321: :telemetry.span/3
    (quantum 3.5.0) lib/quantum/executor.ex:97: anonymous fn/6 in Quantum.Executor.run/5
    (elixir 1.15.2) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
    (elixir 1.15.2) lib/task/supervised.ex:36: Task.Supervised.reply/4

It seems to only happen after Phoenix's code reloader runs.

Not sure how to debug further or workaround. Any advice would be appreciated!

maennchen commented 7 months ago

@cjbottaro Sorry for the long wait.

It seems like the function registered for a job is replaced / deleted by the code reloader.

To counteract this, I would recommend to register the function with a {Module, :function, [args]} tuple to make sure it is still reachable after recompilation.

Does this solve your issue or did you find a solution in the meantime?

maennchen commented 4 months ago

Closed because of inactivity