Ruby 如何 sidekiq -r 引用的文件中 require active support 模块

wdrsam · 2021年05月08日 · 最后由 Catherine 回复于 2021年05月11日 · 379 次阅读

用 sidekiq -r 单独引用我的 A worker 文件,A worker 中引用了一个 demo.rb,在 demo.rb 中想使用 active support 的一些方法。但只要用 sidekiq -r 引用文件,就会说

cannot load such file -- active_support

应该怎么能在-r 的模式下引用到 active_support 呢?

require 是根据$LOAD_PATH 找文件,但我不确定在这种情况下想要引用 active_support 的正确方式是什么

多半是 activesupport 没有安装

gem install activesupport

你的系统里应该是装了 Rails 的,在 Rails 中 active_support 是用 autoload 加载的,自然没有在$LOAD_PATH 里加入 Rails 相关的目录

require 'rails'

应该也会失败,所以 autoload 带进去的 active_support 豪华套餐也没有了。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号