02 Jul 2012 » Dharma Tweet
Today I’ve been working on Dharma-Tweet, a little Node.js app. Its sole purpose in life is to tweet about new talks on Dharmasearch on the behalf of @dharmasearch twitter account. So if your interested in keeping updated on new talks go and follow it!
First I started with Node.js and the Express framework. Then found the Twitter API client library, node-twitter . And that was all I needed. Now it seems to me that to solve a problem you first need to know the problem and once I knew the problem it wasn’t really much of a problem at all. First of all, Twitter helped a lot because they kindly check your tweets to see if it matches any of your recent tweets so you can’t tweet doubles. How useful eh? So this meant I could call Dharma-API, find the last talk added and then immediately tweet that to Twitter. So this is what I’m doing, every 5 seconds! If it’s there it’ll be rejected and if its not it’ll be tweeted. Ideally I wouldn’t of liked to make so many calls but firstly it means that I’ll tweet every talk (hopefully) even if a few are added at once and secondly will keep Dharma-API, which is hosted on Heroku, up and running and responsive. By the way Twitter has no daily limit on tweets but does limit the number of tweets you can tweet at one time.
I have to say coding it was a lot quicker than finding somewhere for it to go and chug along in the background. At first I thought Heroku would take it, for free and that would be that. It seemed that way at first but then it kept mysteriously idling after 1hr and not checking for new talks! Then I found out by Heroku, “If your app has only a single web dyno running, it will idle out – irrespective of the number of worker dynos. You have to have more than one web dyno to prevent idling.” My good friend Tom suggested running a scheduler to keep the app active but I needed to verify my account and my card didn’t work so I went looking elsewhere for a home for dharma-tweet.
Nodejitsu! Actually I’d signed up to these people before. I was put on a waiting list until I finally received access a few days later. I gave up on them before too because of difficulties but I thought I’d give it another go. But you guessed it, there was issues to follow. Confusingly my app worked on my localhost but wouldn’t even start up on theirs. I had a look ‘round the usual places, Github, Stackoverflow and I did see others with similar problems but no real solution. So I went to try #nodejitsu IRC on Freenode and left a message.. and then bingo! No reply, but I noticed in the channel header it said “Cloud Status: New deploys now go to Joyent. Please listen to port 1024.”. Problem solved. Dharma-tweet has been up for more than 2hrs and working nicely (I hope), we’ll be sure when some new talks come in..
. All the best.. Until next time..
