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?
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_nameis called on theUsermodel whereassome_user.some_method_nameis called on an instance of theUsermodel (i.e. the current user object).