Thursday, March 15, 2012

Make scheduled jobs in heroku safer for your wallet.

I recently checked my current usage on Heroku to find that I had used a much higher than expected number of dyno-hours. The project is a RC aviation website that provides some weather data. The forecast data is pulled every hour via FTP by a rake task that is run with a scheduled job in Heroku. Normally this takes around a minute to run and uses about 13 or 14 dyno-hours in a month. Less than half way through this month I found that it had already burned through over 200 dyno-hours.

After digging into the problem I found that the FTP connection was hanging for some reason. After a little research I came up with a solution that works pretty nicely and for more than just hanging FTP connections.

It turns out that ruby's standard library includes a library named Timeout which provides a way to terminate the execution of a thread. Using this library it is very simple to set a time limit for a block of code in a rake test.

task :task_that_takes_a_long_time_sometimes do
  Timeout.timeout(30) do
    #The code that takes a long time to run sometimes

That will raise a Timeout::Error if the code takes longer than 30 seconds to run. The error will cause the rake task to exit, preventing unexpected dyno-hour usage.


Jodi W. Brown said...

So what do you think of what we are hearing here? Are you excited for this film and Debney's score?Executive Employers Review

Talha Yeasin said...

Plagiarism Checker are wonderful tools to hit upon plagiarism in files. However, you need to remember the fact that they can not access password protected areas or some thing that isn't always in their databases. Try this to get all

Maani kamili said...

I do agree with all the ideas you have presented in your post. They’re really convincing and will certainly work. Still, the posts are very short for newbies. Could you please extend them a little from next time? Thanks for the post..

Digital marketing company in Chennai

Sowmiya said...

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. thus it is really a good conclusion work.

Online Reputation Management

Sathya G said...

this is really a very great blog. the information present in this blow will be very useful for us. thank you for sharing with us.
ROI Services in Chennai

Sathya G said...

this is really a very great blog. the information present in this blow will be very useful for us. thank you for sharing with us.
ROI Services in Chennai

Giri Mani 2 said...

This blog explains the details about changing the ways of doing that business. That is understand well and doing some different process. Provides he best output of others. Thanks for this blog.
Digital Marketing Company in Chennai

Shalini said...

Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.

seo company in india

sathya said...

Excellent .. Amazing .. I will bookmark your blog and take the feeds additionally? I’m satisfied to find so many helpful information here within the put up, we want work out extra strategies in this regard, thanks for sharing..

Hadoop Training in Chennai

Base SAS Training in Chennai

tessa tessa said...

This is a great post. I like this topic.This site has lots of advantage. It helps me in many ways.Thanks for posting this again.

SEO Company in India

oracle fusion said...

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. Your write up is a fine example of it.For more details about oracle fusion financial please check our website.

Oracle Fusion Financial Training Institute

Ramya Krishnan said...

Nice Blog, Thanks for sharing your best work.
Oracle DBA Training institute in chennai | Oracle DBA Training institute in velachery

Karthi Keyan said...

Interesting blog post.This blog shows that you have a great future as a content writer.waiting for more updates...
Digital Marketing Company in India

Lauren Gottlieb said...

Wow, cool post. I’d like to write like this too – taking time and real hard work to make a great article… but I put things off too much and never seem to get started. Thanks though. Website Design Kansas City

pocket10 said...

I went over this website and I believe you have a lot of wonderful information, saved to my bookmarks discounts vouchers

Director said...

It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. Thanks for sharing. Hostgator 60 off

NOOR said...

I really impressed after read this because of some quality work and informative thoughts . I just wanna say thanks for the writer and wish you all the best for coming!. Webmetrix Group Best SEO Agency

pixel studios said...

Stunning post. I really impressed. Thank you for your sharing.
Best Digital Marketing Company In Chennai
Ecommerce Website Development Company In Chennai

clothes said...

I will look to see if they're matching what is listed in the Google My Business listing and seek to fix any inconsistencies in those listings. hop over to this site Since the traffic that you get is more qualified, you end up spending less.

Ruhi Sukhla said...

BA Exam Result - BA 1st Year, 2nd Year and 3rd Year Result

Bsc Exam Result - Bsc 1st Year, 2nd Year and 3rd Year Result

TNK Design Desk said...

Thank you so much for these kinds of informative blogs.
we also providesseo services
web company in delhi
web desiging company
web design & development banner
web design & development company
web design & development services
web design agency delhi
web design agency in delhi
web design and development services
web design companies in delhi
web design company delhi
web design company in delhi
web design company in gurgaon
web design company in noida
web design company list
web design company services
web design company website
web design delhi
web design development company
web design development services
web design in delhi
web design service
web design services company
web design services in delhi
web designer company
web designer delhi
web designer in delhi
web designers delhi
web designers in delhi
web designing & development
web designing advertisement
web designing and development
web designing and development company
web designing and development services
web designing companies in delhi
web designing company delhi
web designing company in delhi
web designing company in gurgaon
web designing company in new delhi
web designing company in noida
web designing company logo