Hi, I'm trying to run background process with spawn, I added this
method in my model
[code]
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
[/code]
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
[code]
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
[/code]
the thread does not run and it stops at the first "email", in the log
I see just "email foo"
Any hint?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to