HealthChecker.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* eslint-disable
  2. camelcase,
  3. standard/no-callback-literal,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * DS207: Consider shorter variations of null checks
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const { ObjectId } = require("mongojs");
  14. const request = require("request");
  15. const async = require("async");
  16. const settings = require("settings-sharelatex");
  17. const { port } = settings.internal.trackchanges;
  18. const logger = require("logger-sharelatex");
  19. const LockManager = require("./LockManager");
  20. module.exports = {
  21. check(callback){
  22. const project_id = ObjectId(settings.trackchanges.healthCheck.project_id);
  23. const url = `http://localhost:${port}/project/${project_id}`;
  24. logger.log({project_id}, "running health check");
  25. const jobs = [
  26. cb=>
  27. request.get({url:`http://localhost:${port}/check_lock`, timeout:3000}, function(err, res, body) {
  28. if (err != null) {
  29. logger.err({err, project_id}, "error checking lock for health check");
  30. return cb(err);
  31. } else if ((res != null ? res.statusCode : undefined) !== 200) {
  32. return cb(`status code not 200, it's ${res.statusCode}`);
  33. } else {
  34. return cb();
  35. }
  36. })
  37. ,
  38. cb=>
  39. request.post({url:`${url}/flush`, timeout:10000}, function(err, res, body) {
  40. if (err != null) {
  41. logger.err({err, project_id}, "error flushing for health check");
  42. return cb(err);
  43. } else if ((res != null ? res.statusCode : undefined) !== 204) {
  44. return cb(`status code not 204, it's ${res.statusCode}`);
  45. } else {
  46. return cb();
  47. }
  48. })
  49. ,
  50. cb=>
  51. request.get({url:`${url}/updates`, timeout:10000}, function(err, res, body){
  52. if (err != null) {
  53. logger.err({err, project_id}, "error getting updates for health check");
  54. return cb(err);
  55. } else if ((res != null ? res.statusCode : undefined) !== 200) {
  56. return cb(`status code not 200, it's ${res.statusCode}`);
  57. } else {
  58. return cb();
  59. }
  60. })
  61. ];
  62. return async.series(jobs, callback);
  63. },
  64. checkLock(callback) {
  65. return LockManager.healthCheck(callback);
  66. }
  67. };