env_variable_helper.mjs 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Ensures that the specific MongoDB connection timeout is set.
  3. *
  4. * @param {number} timeoutInMS
  5. * @returns {void}
  6. */
  7. export function ensureMongoTimeout(timeoutInMS) {
  8. if (process.env.MONGO_SOCKET_TIMEOUT !== timeoutInMS.toString()) {
  9. throw new Error(
  10. `must run with higher mongo timeout: MONGO_SOCKET_TIMEOUT=${timeoutInMS} node ${process.argv[1]}`
  11. )
  12. }
  13. }
  14. /**
  15. * Ensures MongoDB queries are running on secondary and the specific connection timeout is set.
  16. *
  17. * @param {number} timeoutInMS
  18. * @returns {void}
  19. */
  20. export function ensureRunningOnMongoSecondaryWithTimeout(timeoutInMS) {
  21. const timeout = parseInt(process.env.MONGO_SOCKET_TIMEOUT, 10) || 0
  22. if (
  23. timeout < timeoutInMS ||
  24. process.env.MONGO_CONNECTION_STRING !==
  25. process.env.READ_ONLY_MONGO_CONNECTION_STRING
  26. ) {
  27. throw new Error(
  28. `must run on secondary with higher mongo timeout: MONGO_SOCKET_TIMEOUT=${timeoutInMS} MONGO_CONNECTION_STRING="$READ_ONLY_MONGO_CONNECTION_STRING" node ${process.argv[1]}`
  29. )
  30. }
  31. }