2008/11/24

Learning Ruby

I'm learning Ruby and I mean it. I decided to write a small lib for scraping websites automatically so created a true Perl-ish class for collection google profiles into a database.

I learned a few things that you might interested in.
First, ruby scraper.rb stole my console so I had to daemonize the script, or even find a runner library. And I found her, named Daemons, a nice lib to run ruby scripts as daemons. Check out my config:

Second, I got back console (hooray) but I wanna see the messages warn or inform me about the state of the script running in the background. Fortunately, Ruby has a nice built in logger I can use for printing to STDOUT. Cool.
Last but not least, I learned a very important thing about HTTP: sometimes it takes a way long to get a document from the cloud for any reason. Timeout for the rescue, baby!

2 comments:

szabi said...

Question two: why do you need a web server for such long running and heavy computing task? You have the console, you have ctrl+z, bg, fg, jobs etc. - probably the problem is with me again.

Janos Hardi said...

Let me explain the Ruby way (hahaha) - like Debian folks do everything with "sudo apt-get" and "no make && make install pls", they want everything in Ruby :) A webserver, a proxy, a daemon, a web framework - everything.

Of course there are people who look forward the best tool for the job at hand, and I admit Ruby is not good in multithreading. We have distributed Ruby but before ruby-1.9 you just simply cheated because of no *real* multithreading.

As of Daemons lib, it is a truly lightweight and simple way to create your own background services - written in Ruby :)