I am building a Rails website which has content that expires at some time in the future. Since this content is cached, by the time it expires I would like a method to sweep the cache at that time. Since it''s based on a date, I cannot use the Rails app itself. I could use polling or sweep the cache every 5 minutes, but maybe there''s a better approach? I would like to know if I can use backgroundrb''s at/cron-like features to schedule one-off execution of a piece of code at a date/time in the future. This would be a sweeper that runs at the expires_at time of my content. I realise I can build a worker that goes into a sleep/wait loop until the desired time, but that''s not really better than polling. Could backgroundrb be helpful?
On Tue, Jul 22, 2008 at 2:23 AM, Joost Baaij <joost at spacebabies.nl> wrote:> I am building a Rails website which has content that expires at some time in > the future. > > Since this content is cached, by the time it expires I would like a method > to sweep the cache at that time. Since it''s based on a date, I cannot use > the Rails app itself. I could use polling or sweep the cache every 5 > minutes, but maybe there''s a better approach? > > I would like to know if I can use backgroundrb''s at/cron-like features to > schedule one-off execution of a piece of code at a date/time in the future. > This would be a sweeper that runs at the expires_at time of my content. > > > I realise I can build a worker that goes into a sleep/wait loop until the > desired time, but that''s not really better than polling.You don''t need an explicit sleep in worker, it will wait anyways on select(). Also, by "one off", you mean, a worker that starts when on schedule and stops after that, you can use "reload_on_schedule true" in worker.
Op 22 jul 2008, om 07:04 heeft hemant het volgende geschreven:> On Tue, Jul 22, 2008 at 2:23 AM, Joost Baaij <joost at spacebabies.nl> > wrote: >> I am building a Rails website which has content that expires at >> some time in >> the future. >> >> I realise I can build a worker that goes into a sleep/wait loop >> until the >> desired time, but that''s not really better than polling. > > You don''t need an explicit sleep in worker, it will wait anyways on > select().I don''t understand, which select are you referring to? Is that a method somewhere in backgroundrb?> Also, by "one off", you mean, a worker that starts when on schedule > and stops after that, you can use "reload_on_schedule true" in worker.Not entirely what I mean, I mean I only need to execute one command at one time in the future. So for example I only need to call the Rails method expire_fragment(''sidebar'') at 2008-07-24 21:00:00 as a one-time event.
On Tue, Jul 22, 2008 at 11:49 AM, Joost Baaij <joost at spacebabies.nl> wrote:> > I don''t understand, which select are you referring to? > > Is that a method somewhere in backgroundrb?I meant select system call, which does IO multiplexing.> >> Also, by "one off", you mean, a worker that starts when on schedule >> and stops after that, you can use "reload_on_schedule true" in worker. > > Not entirely what I mean, I mean I only need to execute one command at one > time in the future. > > So for example I only need to call the Rails method > expire_fragment(''sidebar'') at 2008-07-24 21:00:00 as a one-time event.use add_timer() { foobar() } Thats your one off timer.
Op 22 jul 2008, om 08:22 heeft hemant het volgende geschreven:>> So for example I only need to call the Rails method >> expire_fragment(''sidebar'') at 2008-07-24 21:00:00 as a one-time >> event. > > use add_timer() { foobar() } > > Thats your one off timer.Throw me a bone here :) where is add_timer() defined? Ruby stdlib? Or it is present in backgroundrb somewhere, it''s not in the API docs (at least I can''t find it).
Op 22 jul 2008, om 09:11 heeft hemant het volgende geschreven:>>>> >>> use add_timer() { foobar() } >>> >>> Thats your one off timer. >> >> Throw me a bone here :) where is add_timer() defined? Ruby stdlib? >> >> Or it is present in backgroundrb somewhere, it''s not in the API >> docs (at >> least I can''t find it). >> > > http://backgroundrb.rubyforge.org/scheduling/ > > Look at at beginning of the docs. ;)I was completely blind! But now my eyes are open :-) Thanks a lot!!
Joost Baaij wrote:> I am building a Rails website which has content that expires at some > time in the future. > > Since this content is cached, by the time it expires I would like a > method to sweep the cache at that time. Since it''s based on a date, I > cannot use the Rails app itself. I could use polling or sweep the > cache every 5 minutes, but maybe there''s a better approach? > > I would like to know if I can use backgroundrb''s at/cron-like features > to schedule one-off execution of a piece of code at a date/time in the > future. This would be a sweeper that runs at the expires_at time of my > content. > > > I realise I can build a worker that goes into a sleep/wait loop until > the desired time, but that''s not really better than polling.I think one issue is that the backgroundb will loose it''s pending tasks if it''s rebooted? Does this cause your app a problem? Have you considered memcached caching which has time based expiry (could integrate better). Or I think it''s not so hard to wrap the builtin partial caching to include time based expiration (see some of the plugins for inspiration, just need to choose a good place to store your metadata) Anyway, feels like although bdrb can do this it might not be the best solution? Good luck Ed W