Josh Sharpe wrote:
> class PendingOrder < ActiveRecord::Base
>   def sleep_until_processed
>     sleep 0.5
>     while !processed?
>       reload
>       sleep 0.25
>     end
>   end
> end

> Robert Walker wrote:
>> In any case I would recommend adding some "circuit breaker" code to your 
>> method to prevent blocking forever. Maybe some sort of timeout/watchdog 
>> to limit the amount of time this method could block.

And, if your Rails application is single treaded then your 
sleep_until_processed method could block your entire Rails application 
never allowing other parts of the application to perform the work 
necessary to update the pending_orders table.

Maybe you should consider offloading this work to a background process 
using something like delayed_job or similar.
-- 
Posted via http://www.ruby-forum.com/.

-- 
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