Created
June 15, 2012 16:18
-
-
Save mike-north/2937359 to your computer and use it in GitHub Desktop.
Check heroku platform status, and respond accordingly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A function to check heroku status, and return results to a callback | |
*/ | |
function heroku_status(callback) { | |
//YQL is necessary becasue heroku status JSON data is not padded | |
$.getJSON("http://query.yahooapis.com/v1/public/yql", | |
{ | |
q:"select * from json where url=" + | |
"\"https://status.heroku.com/api/v3/current-status.json\"", | |
format:"json" | |
}, | |
function (data, request_status, xhr) { | |
if (data.query.results) { | |
callback(data.query.results.json.status, //Heroku platform status | |
data.query.results.json.issues, //Heroku platform issues | |
request_status, //request status (i.e., "success") | |
xhr //jqXHR object | |
); | |
} else { | |
console.error('Problem accessing heroku status information'); | |
} | |
} | |
); | |
} | |
/** | |
* Example usage, doing something different depending on heroku production status | |
*/ | |
$().ready(function () { | |
heroku_status( | |
/** | |
* An example callback function | |
* @param status Heroku platform status in "red", "yellow" or "green" form. | |
* i.e., {"Development": "yellow", "Production": "green"} | |
* @param issues JSON data representing any issue currently being worked on | |
* @param response_type will probably be "success" | |
* @param xhr jqXHR object | |
*/ | |
function (status, issues, response_type, xhr) { | |
switch (status.Production) { | |
case "yellow": | |
console.log("There may be some problems with the site"); | |
break; | |
case "red": | |
console.log("The application is down"); | |
break; | |
case "green": | |
console.log("All systems go"); | |
break; | |
default: | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment