Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. module.exports.pool = pool = mysql.createPoolCluster {
  2. restoreNodeTimeout: 5000
  3. }
  4.  
  5. pool.add 'master', {
  6. host: config.get 'mysql.master.host'
  7. user: config.get 'mysql.master.id'
  8. password: config.get 'mysql.master.password'
  9. database: config.get 'mysql.master.scheme'
  10. debug: DEBUG
  11. acquireTimeout: 2000
  12. waitForConnections: true
  13. connectionLimit: if PROD then 80 else 20
  14. queueLimit: 0
  15. timezone: 'Asia/Seoul'
  16. }
  17.  
  18. pool.add 'slave', {
  19. host: config.get 'mysql.slave.host'
  20. user: config.get 'mysql.slave.id'
  21. password: config.get 'mysql.slave.password'
  22. database: config.get 'mysql.slave.scheme'
  23. debug: DEBUG
  24. acquireTimeout: 2000
  25. waitForConnections: true
  26. connectionLimit: if PROD then 30 else 20
  27. queueLimit: 0
  28. timezone: 'Asia/Seoul'
  29. }
  30.  
  31. pool.on 'enqueue', ->
  32. logger.warn 'Waiting for available connection slot. Make sure your connection is released.'
  33.  
  34. module.exports.getConnection = (selector = 'master', pattern = 'RR') ->
  35. if selector is 'cache'
  36. return module.exports.getCacheConnection()
  37. else
  38. pool.of(selector, pattern).getConnectionAsync()
  39. .then (conn) ->
  40. return conn
  41. .disposer (db, promise) ->
  42. db.release()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement