env_variable_helper.mjs 998 B

12345678910111213141516171819202122232425262728293031
  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. if (
  22. process.env.MONGO_SOCKET_TIMEOUT !== timeoutInMS.toString() ||
  23. process.env.MONGO_CONNECTION_STRING !==
  24. process.env.READ_ONLY_MONGO_CONNECTION_STRING
  25. ) {
  26. throw new Error(
  27. `must run on secondary with higher mongo timeout: MONGO_SOCKET_TIMEOUT=${timeoutInMS} MONGO_CONNECTION_STRING="$READ_ONLY_MONGO_CONNECTION_STRING" node ${process.argv[1]}`
  28. )
  29. }
  30. }