Browse Source

add timeout to health check requests and always try the delete

Henry Oswald 11 years ago
parent
commit
4f5669591a
1 changed files with 10 additions and 7 deletions
  1. 10 7
      services/docstore/app/coffee/HealthChecker.coffee

+ 10 - 7
services/docstore/app/coffee/HealthChecker.coffee

@@ -10,6 +10,7 @@ logger = require "logger-sharelatex"
 
 
 module.exports = 
 module.exports = 
 	check : (callback)->
 	check : (callback)->
+		getOpts = -> {url:url, timeout:3000}
 		doc_id = ObjectId()
 		doc_id = ObjectId()
 		project_id = ObjectId(settings.docstore.healthCheck.project_id)
 		project_id = ObjectId(settings.docstore.healthCheck.project_id)
 		url = "http://localhost:#{port}/project/#{project_id}/doc/#{doc_id}"
 		url = "http://localhost:#{port}/project/#{project_id}/doc/#{doc_id}"
@@ -17,19 +18,21 @@ module.exports =
 		logger.log lines:lines, url:url, doc_id:doc_id, project_id:project_id, "running health check"
 		logger.log lines:lines, url:url, doc_id:doc_id, project_id:project_id, "running health check"
 		jobs = [
 		jobs = [
 			(cb)->
 			(cb)->
-				opts = 
-					url:url
-					json: {lines: lines}
+				opts = getOpts()
+				opts.json = {lines: lines}
 				request.post(opts, cb)
 				request.post(opts, cb)
 			(cb)->
 			(cb)->
-				request.get {url:url, json:true}, (err, res, body)->
+				opts = getOpts()
+				opts.json = true
+				request.get opts, (err, res, body)->
 					if res.statusCode != 200
 					if res.statusCode != 200
 						cb("status code not 200, its #{res.statusCode}")
 						cb("status code not 200, its #{res.statusCode}")
 					else if _.isEqual(body.lines, lines) and body._id == doc_id.toString()
 					else if _.isEqual(body.lines, lines) and body._id == doc_id.toString()
 						cb()
 						cb()
 					else
 					else
 						cb("health check lines not equal #{body.lines} != #{lines}")
 						cb("health check lines not equal #{body.lines} != #{lines}")
-			(cb)->
-				request.del url, cb
 		]
 		]
-		async.series jobs, callback
+		async.series jobs, (err)->
+			if err?
+				callback(err)
+			request.del getOpts(), callback