MongoHealthCheck.coffee 976 B

1234567891011121314151617181920212223242526
  1. Settings = require "settings-sharelatex"
  2. PersistenceManager = require "./PersistenceManager"
  3. module.exports = MongoHealthCheck =
  4. isAlive: (_callback = (error) ->) ->
  5. # We've seen very occasionally the doc-updater losing its connection to Mongo.
  6. # E.g. https://sharelatex.hackpad.com/29th-Aug-2015-0650-0740-fHlw8RL8zuN
  7. # It seems that the mongo callbacks never returned.
  8. # Mongo is only called in the persistence manager, so we do a read-only
  9. # test call, check that it's working, and returns in a reasonable time.
  10. callback = (args...) ->
  11. _callback(args...)
  12. _callback = () ->
  13. doc_id = Settings.smokeTest?.doc_id
  14. if !doc_id?
  15. return callback(new Error("No test doc_id configured"))
  16. PersistenceManager.getDocVersionInMongo doc_id, (error, version) ->
  17. return callback(error) if error?
  18. callback(null)
  19. timeout = Settings.smokeTest?.timeout or 10000
  20. setTimeout () ->
  21. callback(new Error("Mongo did not return in #{timeout}ms"))
  22. , timeout