Hi, I’m trying to run background process with spawn, I added this
method in my model
include Spawn
class List < ActiveRecord::Base
has_many :members
has_many :people, :through => :members
def import(emails)
spawn do
emails.split("\r").each do |email|
logger.info "\n email #{email}\n"
sleep(5)
end
end
end
end
when it’s called @list.import(emails) i can see that the log keep
going even if the page has already loaded but if I need to make some
operations on the model
include Spawn
class List < ActiveRecord::Base
has_many :members
has_many :people, :through => :members
def import(emails)
spawn do
emails.split("\r").each do |email|
logger.info "\n email #{email}\n"
person = Person.create(:email => email, :is_enabled => true)
m = Member.create! :list => self, :person => person
sleep(5)
end
end
end
end
the thread does not run and it stops at the first “email”, in the log
I see just “email foo”
Any hint?