ruby-on-rails - Sidekiq -ra 单个 demo_worker.rb 文件,并且需要该工作人员的积极支持不起作用
问题描述
我想在我的 demo_worker.rb 中要求 active_support。
require 'sidekiq'
require 'active_support'
class DemoWorker
end
然后我跑了sidekiq -r ./demo_worker.rb
它告诉我不能需要active_support,我也尝试需要rails,但仍然没有工作。如何在 sidekiq 的普通模式下需要 active_support?
这是我得到的确切错误
cannot load such file -- active_support/core_ext (LoadError)
我环顾四周,找不到有用的东西。
解决方案
发生此错误的原因是 gemactivesupport
尚未安装(在您的本地计算机上),因此只需运行 command gem install activesupport
,就可以了。
但请注意,active_support
在 Rails 中使用autoload
,所以如果我们要在 Rails 之外使用它的子模块,我们需要直接要求它们,例如我想使用Integer#hours
我需要要求的扩展active_support/core_ext/integer/time
require 'sidekiq'
require "active_support/core_ext/integer/time"
class Demo
include Sidekiq::Worker
def perform(how_hard="super hard", how_long=1)
sleep how_long
puts "Workin' #{how_hard} #{8.hours}"
end
end
推荐阅读
- wix - 如何在“WIX Burn Bootstrapper”中自动升级第三方“可执行包”
- python - Python AttributeError:“str”对象没有属性“decode”
- c++ - C++ dll定义静态成员
- java - 在tomcat中,如何在其他项目中获取类的注释
- ruby-on-rails - 使用 remotipart gem 和 Paperclip 在 Ruby on Rails 中上传图像
- mysql - SQL选择两列组合的最高行
- c - 试图打印出用户空间内存的内容
- c++ - 从 C++ 服务器获取
- awk - 如何使用 AWK 用空格右填充字段
- python - 使用 sklearn 进行预测建模管道