Skip to content

Commit

Permalink
JS foo
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermef committed Sep 30, 2012
1 parent 85cf2ed commit a7723f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
7 changes: 2 additions & 5 deletions lib/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ class Connection
attr_accessor :status_code

def initialize(url)
uri = URI.parse(url)
uri = URI(url)
begin
response = Net::HTTP.start(uri.host, uri.port) {|http|
http.get(uri.path)
}
status = response.code
status = Net::HTTP.get_response(uri).code
rescue SocketError
status = '404'
ensure
Expand Down
46 changes: 24 additions & 22 deletions static/javascripts/views/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
var healthCheckCallback = function(response){
var status = response.status;
this.addClass(status);
HealthChecker = function() {
this.init();
};

// if (status != "ok"){
// var $errors = $('<span>').addClass('errors');
HealthChecker.prototype = {

// this.append
// }
};
init: function() {
$('.project').each(this.setHealthcheck.bind(this));
},

var healthCheck = function(project) {
var url = project.data('healthcheck');
project.removeClass('down').removeClass('ok');
$.ajax({
url: url,
context: project
}).done(healthCheckCallback);
};
setHealthcheck: function(i, element){
var project = $(element);
setInterval(this.healthCheck.bind(this, project), 5000);
},

(function(){
$('.project').each(function(){
var project = $(this);
setInterval(function(){ healthCheck(project);}, 5000);
});
})();
healthCheck: function(project){
var url = project.data('healthcheck');
project.removeClass('down').removeClass('ok');
$.ajax({
url: url,
context: project
}).done(this.healthCheckCallback);
},

healthCheckCallback: function(response){
this.addClass(response.status);
}
};

new HealthChecker();

0 comments on commit a7723f8

Please sign in to comment.