On 4/25/07, Jonathan Stott <[EMAIL PROTECTED]> wrote:
> > I would recommend a cronjob, solving it with a long running process
> > will likely get you in trouble with memory leaks and such.
> >
> > Manfred
>
> I'm not quite sure how this is relevant (though I fully admit I might
> be missing some of the complexities of ruby, camping and/or threads),
> since I'd like the process to be part of a Camping App, which is
> presumably going to be running fairly consistently anyway. Unless
> you're suggesting an entirely external app that does the fetching and
> somehow pushes the results into the database of the camping
> application so it can display it?
The problem with long-running multi-threaded Ruby processes tends to
be that the threads themselves fail to be garbage collected,
eventually resulting in memory problems. If you only have one
background thread doing the updates, you really shouldn't have to
worry about it as a major source of leaks.
> Anyway, I know I can set up a cronjob with curl to regularly get the
> page and thus make the controller logic fetch the feeds, I was just
> wondering if there was a way to do it in the app itself, since I like
> applications that are self-contained.
It really shouldn't be hard. Something like the following in your
application startup code should be enough:
---
# Note: this line needs to come before Camping does its auto-magical SQLite
# connection stuff, so you may need to experiment
ActiveRecord::Base.allow_concurrency = true
# This line just starts a background thread that will run once per hour in the
# background, calling your refresh method each time
Thread.new { loop { MyApp::Controllers::FeedReader.refresh; sleep 3600 } }
---
-Lennon
_______________________________________________
Camping-list mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/camping-list