From: Mat Brown Date: 2010-02-27T04:53:45+09:00 Subject: Re: scheduling asynchronous delayed execution Check out resque-scheduler: http://github.com/bvandenbos/resque-scheduler Generally you'll want to use a standalone daemon to do any sort of background work; doing it in threads / forking considered harmful in Rails. Mat On Fri, Feb 26, 2010 at 14:50, Nick Brown wrote: > What is the best way to schedule something for delayed asynchronous > execution? Basically, I want to say "in 20 seconds, execute this > function / block / proc / lambda / webhook or whatever". > > Also: this will be used by a rack-based web app, so I need a solution > that will keep working if Passenger restarts instances of the > application. Would a Thread.new(delay) {|delay| sleep delay; ...} type > of solution work in such a scenario? Does using Thread like this consume > lots of memory? > > How have you solved this in the past? I would like to avoid installing > daemons if possible. > > I was thinking of doing something like below, but I'm not sure it will > be reliable in a web app environment: > > def call_async(code, delay=0) >  Thread.new(delay, code) {|d,c| sleep d; c.call} > end > -- > Posted via http://www.ruby-forum.com/. > >