Answer the question
In order to leave comments, you need to log in
How to write to the database inside the background worker?
I am developing a small utility in Ruby. Its two main tasks are: periodically executing an HTTP request with saving the response in the database and displaying the received data in the web interface.
As tools I chose:
require 'sidekiq'
require 'awesome_model'
class AwesomeWorker
include Sidekiq::Worker
def perform model_id
model = ObjectSpace._id2ref model_id
model.update_attributes! { data_key: "data value" }
end
end
AwesomeWorker.perform_async AwesomeModel.new.object_id.to_i
Answer the question
In order to leave comments, you need to log in
The error is elementary and is not associated with any of the listed tools.
What to do?
require 'sidekiq'
require 'awesome_model'
AwesomeModel # => ???
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question