将HTTParty与delayed_job结合使用
我正在尝试使用 delayed_job
和 HTTParty
执行此操作:
HTTParty.delay.get('http://example.com')
它成功保存到 DJ 表,如下所示:
--- !ruby/object:Delayed::PerformableMethod
object: !ruby/object:Module {}
method_name: :get
args:
- http://example.com
问题是它没有提及 HTTParty
在该处理程序中,因此当我尝试运行作业时,我收到此错误:
undefined method `get' for #<Module:0x007fff1095b9a8>
我正在使用 delayed_job (3.0.0.pre)
, rails 3.0.6
应用中的 delayed_job_active_record (0.2.1)
和 httparty (0.7.7)
。
那么我怎样才能让delayed_job和HTTParty很好地协同工作呢?
I'm trying to do this with delayed_job
and HTTParty
:
HTTParty.delay.get('http://example.com')
It successfully saves to the DJ table as this:
--- !ruby/object:Delayed::PerformableMethod
object: !ruby/object:Module {}
method_name: :get
args:
- http://example.com
The problem is that it doesn't have any mention of HTTParty
in that handler, so when I try to run the jobs, I get this error:
undefined method `get' for #<Module:0x007fff1095b9a8>
I'm using delayed_job (3.0.0.pre)
, delayed_job_active_record (0.2.1)
and httparty (0.7.7)
in a rails 3.0.6
app.
So how can I make delayed_job and HTTParty play nice together?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将代码包装在实例方法中。
示例:
然后你只需在其他地方调用它,例如:
或者如果你需要访问成功的 get 请求内容
编辑
如果你打算将其设为类方法,那么代码将如下所示:
示例:
然后您只需在其他地方调用它,例如:
或者如果您需要访问成功的 get 请求内容,
区别在于
User.some_method_name
在User
模型上调用,而some_user.some_method_name
在User
模型的实例(即当前用户对象)上调用。Wrap the code in an instance method.
Example:
Then you just call it somewhere else like:
or if you need access to the successful get request contents
Edit
If you're going to make it a class method, then the code will be like this:
Example:
Then you just call it somewhere else like:
or if you need access to the successful get request contents
The difference is that
User.some_method_name
is called on theUser
model whereassome_user.some_method_name
is called on an instance of theUser
model (i.e. the current user object).