08 Feb, 2007

Published at 03:53AM

Tagged with site, problems, and ruby

This post has 3 comments

Having trouble going Home

I can’t seem to access the homepage. It has been acting funny over the last few days (maybe even weeks). It was up and running fine last night around 12:30 AM, but was down for an hour or two yesterday afternoon. Go figure.

I can’t blame this one on Dreamhost, but it has to be someone’s fault other than mine, right? So I think I’m going to blame net/http. Originally, I was going to blame the flickr api, but hitting it directly returns what I would expect. However, the problem is generated in the setup_flickr method, which uses net/http. That doesn’t make sense, though, and I’ll tell you why. Because I’ve been using it for over 7 months now, and I’ve never had a problem with it before—that’s why. I do have a confession to make, though. I have Rails frozen at 1.1.4. It’s somewhat old, I know, but I quit making major updates as of 6-7 months ago, so I never had the dire need to upgrade it. But that seems irrelevant, since that’s the whole point of freezing Rails: to always work with whatever version your app was built with.

The del.icio.us integration uses the Rubilicious gem, and seems to be fine; but I’m gathering the flickr data the hard way, using Net::HTTP::Get and parsing it out with REXML. So, it’s narrowed down to the setup_flickr method, since taking it out proves everything to be fine. Here’s what shows up in the logs:

Errno::ETIMEDOUT (Connection timed out - connect(2)):
    /usr/lib/ruby/1.8/net/http.rb:560:in `initialize'
    /usr/lib/ruby/1.8/net/http.rb:560:in `open'
    /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
    /usr/lib/ruby/1.8/timeout.rb:48:in `timeout'
    /usr/lib/ruby/1.8/timeout.rb:76:in `timeout'
    /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
    /usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
    /usr/lib/ruby/1.8/net/http.rb:542:in `start'
    /app/controllers/application.rb:50:in `setup_flickr'
    /app/controllers/application.rb:49:in `each'
    /app/controllers/application.rb:49:in `setup_flickr'
    /app/controllers/application.rb:88:in `setup_layout'

Is this something I should wait out? Or do you know of any big changes to net/http that would cause me to have to hack away using a different approach? Or do you suspect something else to be the problem? I would appreciate any thoughts on this—maintaining my site is starting to feel like a part-time job.

Update (02/08/07 @ 10:04 AM): Of course everything is back now. I just needed to post about it, I guess.

Comments

Chris Thursday, 08 Feb, 2007 Posted at 05:12AM

So, are you not caching the flickr data? I thought you were doing that. I would recommend that you setup a cron job to pull in flickr data and write it to a cache file in your Rails app every 30 minutes or something like that. Then, you would simply read in the file and kick out the results.

The cron job would simply execute a Ruby script that would retrieve and process the flickr data into whatever format you want (you can even have it simply dump a Ruby object such as a hash directly to a file, which can be reloaded directly – see the Marshal).

Ryan Thursday, 08 Feb, 2007 Posted at 06:45AM

That sounds like a good idea. I’ll have to play around with that, as I know very, very little about cron jobs and how that whole process would work. I think that’s the type of solution I wanted from the beginning, but never stopped to figure something out.

So what you’re saying is the contents of my setup_flickr method would essentially be put in a separate script, and instead of what I’m doing (loading up an array for the view) with the results, I could dump a hash to some file. Then in my setup_flickr method, I’d use Marshal.load(file) to setup variables for the view?

That may seem completely redundant to what you’ve just told me, but I’m brand new to Marshal and cron jobs, and it’s probably the overall process that would confuse me the most.

Thanks again for the advice.

Chris Thursday, 08 Feb, 2007 Posted at 07:15AM

Yes, that’s all you need to do. The processing code that you are using right now would go into a separate script (which I would probably put in the scripts directory or maybe a new directory named jobs or tasks). Setting up the cron is actually pretty easy – here’s one I had for the devbook

*/5 * * * * wget http://dev.scharfie.com/accounts/login -O - -q >/dev/null 2>&1

The script itself will process the flickr data into a hash or whatever you are currently using, and then Marshal.dump the object to the cache file. I recently used the Marshal library for something, but I honestly cannot remember what it was for :-p

Do you have something to say about this post?
Retype the image to the right Spam Hint: Are You Human? Textile Formatting Tips

or

Ryan Heath | Site Management A Ruby on Rails production.

This site is a Formed Function. Formed Function LLC | @formedfunction | Get in Touch