I am trying to make a simple import background job to import some csv information using resque.
The job runs, but once I edit an object it seems like its ruined or something...
Once this job runs, it finds the user with the first lin... then at @user.name it doesn't get set, and then it can't save. I can run this code in my console and it works great, only broken in resque. Is there a limitation that you can't work with object or write to a database with resque? wasted 6 hours so far trying myriads of things...please help.
def self.perform(chunk)
chunk.each do |i|
@user = User.where(:email => i[:email].to_s).first_or_initialize
@user.name = i[:name].to_s
if @user.save
puts @user.email
entity = Entity.find_by_email_domain(@user.email)
eur = EntityUser.where(:entity_id => entity.id, :user_id => @user.id).first_or_initialize
if eur.save
puts "Start: BLARGITY End"
topic = Topic.where(:number => i[:course_number].to_s).first_or_initialize
eu = TopicUser.where(:topic_id => topic.id, :user_id => user.id, :role_i => 1).first_or_initialize
else
eu = TopicUser.where(:topic_id => topic.id, :user_id => user.id).first_or_initialize
end
eu.save
end
end
end
end
I just tried with doing a find instead like this, and you can see the error now..
NoMethodError: undefined method `name=' for nil:NilClass
@user = User.find_by_email(i[:email])
puts "sdfdsf"
@user.name = i[:name]
puts @user.name
I was using smarter_csv to send in 'chunk' which was a hash. I guess when redis serializes a hash, you need to symbolize it before you start using it again.
chunk.each do |i|
i.symbolize_keys!
@user = User.find_by_email(i[:email])
@user.name = i[:name]
works after symbolizing it!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.