Welcome Guest | Login

Cron jobs in the rails environment on Hosting Rails

Hello,

Coming up in the next few days I'm going to need to be able to run a scheduled script that must interface with my Rails environment every night.

I know that cron can do this, but having to write a script outside of my Rails environment (especially one that doesn't automatically load Rails) is not preferable.

I was hoping to use BackgroundDRb, but before I choose an option, I was wondering if there is a recommended way to do this on Hosting Rails.

Please let me know if there is, or this has already been done, so I know which option to choose.

Thanks

2008-07-11 03:44 AM

Hi,

You can run scripts placed under your home directory as cron by calling it in your crontab file. To OPen a cronjob file do

crontab -e

If you still have questions, please explain us a little more about the script and the requirements it should meet.



2008-07-11 04:11 AM

Thanks for the response.  I realize I can use cron, however I'm trying to avoid doing that.

The script will essentially need to go through a database table every night, read each record and update it through an external datasource.

Since I'm using the database (and consequentially my RoR models and environment), I need to be able to run it through the Rails environment.

From what I understand about cron, this will only run a Ruby script without loading Rails.

This was why I was considering BackgroundDRb.  I'll need to run the script in the context of Rails, not as a standalone Ruby file.

Hope this makes sense.

2008-07-11 04:25 AM

Yes, you can try BackgroundDRb [ http://backgroundrb.rubyforge.org ]

2008-07-11 06:33 AM

Great, thanks

2008-07-16 08:47 AM

I considered this approach too but it just seemed to add extra complexity to my deployment.

Instead I created a controller and an action in my rails app that performs all the necessary database updates, then from my crontab I invoke the action using wget and the url to my action. Works very smooth, is very easy to test, doesn't need any extra processes and can be run adhoc if needed.

Martin

2008-07-16 09:51 AM

Martin, thanks for that info.  I did consider that but I'd need to have the progress information that BackgroundDRb provides, and I like trying these technologies :)

Sorry to revive an old thread, however I did have another question.  What port should I be using for the BackgroundDRb process?  I'm already using my assigned port for a Ferret server.  Is there a way I can purchase another port?

Thanks

2008-08-04 07:01 PM

You have only 50 MB dedicated memory added to your account so  you're allowed to run only a single instance daemon using the port. If you wish to run another process as daemon, you'll need to add 50 MB more dedicated memory into your account. Also, note that you can use your assigned port itself to run multiple process by just appending 0,1,2.. to the 4 didgit port. for eg:
if your assigned port is 4123 you can use 41230,41231,41232 etc as dedicated ports for different processes.  

2008-08-04 07:18 PM

Varun, as always, you have been very helpful.

Thanks!

2008-08-04 08:05 PM

All, thanks for the help on this.  Would like some guidance/advice on my implementation as follows:

I'll be buying additional memory to run a BackgrounDRb process, and will run it on a new port as mentioned.  The background process essentially does the following: every night, for each record in a certain table in my database, it goes out and makes several HTTP connections to external data sources to refresh those records.

At its worst, the background process would launch all connections simultaneously, thus incurring a significant memory hit.  However, I can throttle it so that it only launches the connections in batches.  For example, if there are fifty connections, I can launch the first ten, wait for those to finish, launch the next ten, wait for those to finish, and so forth, until all connections are done.

My question is: per my account (and I can upgrade, if need be, just let me know) how much system memory do you recommend I use at any one time?  Do you terminate processes that use more than a certain amount?  What's your guidance in terms of this.

I assume that memory is allocated on an as needed basis on the system?

Thanks for your assistance.

2008-08-14 04:20 PM

This kind of implementation should be done on a VPS unless you want to slow it way down (do only 1 process at a time).  Even ten processes going will raise flags in a shared env and may get killed off.   Of course if those ten processes don't use too much CPU and you're within reasonable range of your memory limit you should be OK.  

2008-08-14 05:00 PM

Thanks for the response.  The VPS solution looks doable.  Once we get closer to going live I'll have to follow up with that.

As for my memory limit, where would I go about finding how much that is?

Thanks

2008-08-14 05:09 PM

You could check the amount of memory that is assigned for your account via the account center.

2008-08-14 06:10 PM

HostingRails Support

Hello Guest! In order to post you must be an active client with us, please log in or sign up today!