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 CheckTheSock.com 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
  end
end

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.

30 comments:

Anna Schafer 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

e55y5 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 http://www.plagiarism-checker.me/

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

Unknown 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

Unknown 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

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

Ramya Krishnan said...

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

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

fortnite 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

fortnite 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.

Gerardoavery cristian said...

Page content is central to all the on-page SEO processes. their video channel Promote content to website visitors by retargeting, promoting it to people within your area (note: it is a must to use great content, so if you have not created such, start now) and utilize all possible advertising tools to get likes, views and shares for your content.

Watson Henry said...

If the server that handled the client's original request becomes unavailable, subsequent requests can be automatically routed to another server without the client knowing or caring Toronto IT Support

Arena Infosolution said...


Arena Infosolution is the best company for the Digital Marketing Internship in Jaipur. Our company offers an internship that gives a good job after completion of the internship which gives a path to your career and makes your future bright in digital marketing.

We offer Digital Marketing Internship in Jaipur that lays a path that drives you to the world of opportunities. Here you will get a chance to learn the skills that will be helpful for building a remarkable career in Digital Marketing.

For more info:-
Contact : +91-8094351234, 8955536801
https://arenainfosolution.com/digital-marketing-internship-in-jaipur/

naksha dekho said...

hy thanks for sharing useful information.very helpfuluseful

naksha dekho said...

hy thanks for sharing this information.very helpful and useful thanks

naksha dekho said...

hy thanks for sharing this information.very helpful and useful thanks

naksha dekho said...

nakshahomemap@gmail.com it is really helpful. the information in this article is satisfied me. And the information it is very interesting. Thanks for this kind of article. thanks

arshiya said...

This is good information and really helpful for the people who need information about this.
devops skills
career objective
tableau course duration
how to improve spoken english
blue prism interview questions
blue prism interview questions and answers
javascript interview questions

bhawanadigitalmarketing said...

Arena Infosolution Company provides very good service and it is also an institute that teaches practical work.

bhawanadigitalmarketing said...

https://arenainfosolution.com/website-development-company-in-jaipur/
Arena Infosolution Company provides very good service and it is also an institute that teaches practical work.

sportstotolink said...

You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. 토토

Sikandar Ali said...

Really Good Work Done By You...However, stopping by with great quality writing, it's hard to see any good blog today.
Freeprosoft
Freemake Video Converter Crack
Crack Softwares Free Download

Anonymous said...

Play casino - No.1 for the Casino Guru
No longer have the opportunity herzamanindir.com/ to go to the casinos or read the communitykhabar reviews of the slots you love. But they're 바카라 사이트 not always the same. Sometimes you have a new online https://sol.edu.kg/

slot said...

เกมสล็อตน้องใหม่ เล่นได้สนุก พีจีทางเข้า กับเกมส่งตรงจากประเทศอังกฤษ สนมากับเกมที่น่าตื่นตาตื่นใจ ที่หาไม่ได้จากที่ไหน เพลิตเพลิน และทำเงินได้จริงฝากถอนเงินง่าย ด้วยระบบอัตโนมัติ สนุกแปลกใหม่เร้าใจ เล่นได้เลยตอนนี้ผ่านเว็บไซต์ PGSLOTGAMES

Phuwadon said...

ต้องการเล่นเกมเพื่อรับเงิน ทางเข้าเล่นpg https://www.pgslot168game.com/login-pgslot/ มาที่นี่และเล่นเกมสล็อตออนไลน์กับเรา เพียงหมุนและหมุนสปินเกมให้ได้สัญลักษณ์ที่กำหนดโดยเกมทางตัวเกมกำหนด คุณสามารถลุ้นรับรางวัลและรางวัลใหญ่มากมาย เช่น รางวัลแจ็คพอตมากมาย สามารถแลกเป็นเงินสดได้ที่ PG SLOT ผู้ให้บริการเกมสล็อตออนไลน์อันดับหนึ่งของประเทศ

สล็อตเว็บตรง said...

สล็อตเว็บตรง ส่วนใหญ่ในตอนนี้กำลังเป็นที่นิยมและฮิตสำหรับผู้เล่นจำนวนมากเพราะเป็นเว็บตรงPGที่มีตัวเกมส์ที่น่าเล่นและตัวเกมส์อีกหลากหลายมากมายที่อยู่ในเว็บตรงPGและมีเกมส์ที่มีผู้เล่นนิยมกันเป็นส่วนใหญ่อย่างเช่นตัวเกมส์Lucky Neko ที่ผู้เล่นส่วนใหญ่เล่นตัวเกมส์ Lucky Neko เพราะเป็นตัวเกมส์ที่มีการปล่อยฟรีสปินให้ลูกค้ากันเป็นอย่างหนัก

JAke Leonel said...

Actually Magnificent.
rotating masturbator cup
water based lubricant.