系统更新后Oban启动报错:expected :strategy option to be given
问题描述
更新MacOS Sequoia 15.1.1后,启动服务器时出现Oban启动失败的错误,此前运行正常。错误信息如下:
(Mix) Could not start application main: Main.Application.start(:normal, []) returned an error: shutdown: failed to start child: Oban (EXIT) shutdown: failed to start child: {:via, Registry, {Oban.Registry, {Oban, Oban.Nursery}}} (EXIT) shutdown: failed to start child: {Oban.Registry, {Oban, Foreman}} (EXIT) an exception was raised: ** (ArgumentError) expected :strategy option to be given (elixir 1.12.2) lib/dynamic_supervisor.ex:516: DynamicSupervisor.init/1
application.ex中的配置:
{Oban, Application.fetch_env!(:main, Oban)}
config.exs中的配置:
config :main, Oban, repo: Data.Repo, queues: [ events: 10, campaigns: 5, mindbody_import: 5, at_risk_chaflow: 1, auto_close_conversations: 1 ], plugins: [ {Oban.Plugins.Cron, crontab: [{"59 11 * * SUN", Main.WeeklyReports}]} ]
环境信息:Elixir 1.12.2,Oban 2.18.3。错误提示DynamicSupervisor缺少:strategy选项,需排查修复。
排查与修复方案
核心原因:Elixir 1.12.2要求DynamicSupervisor必须显式指定
:strategy选项,但Oban 2.18.3在较新Elixir版本中会默认处理该配置,旧版本Elixir需手动补充。修复步骤:
- 在
config.exs的Oban配置中添加:engine字段,显式设置DynamicSupervisor策略:config :main, Oban, repo: Data.Repo, queues: [ events: 10, campaigns: 5, mindbody_import: 5, at_risk_chaflow: 1, auto_close_conversations: 1 ], plugins: [ {Oban.Plugins.Cron, crontab: [{"59 11 * * SUN", Main.WeeklyReports}]} ], engine: {Oban.Engines.Basic, strategy: :one_for_one} - 保存配置后重启服务器,验证Oban是否正常启动。
- 在
备选方案:若上述方法无效,可升级Elixir版本至1.13+(该版本起DynamicSupervisor默认使用
:one_for_one策略),升级前需确认项目依赖兼容性。
内容的提问来源于stack exchange,提问作者ch wajeeh
相关产品推荐
相关产品推荐

