destroy-manager.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. module.exports = {
  2. friendlyName: 'Destroy manager',
  3. description: 'Destroy the specified connection manager and destroy all of its active connections.',
  4. inputs: {
  5. manager: {
  6. friendlyName: 'Manager',
  7. description: 'The connection manager instance to destroy.',
  8. extendedDescription: 'Only managers built using the `createManager()` method of this driver are supported. Also, the database connection manager instance provided must not have already been destroyed--i.e. once `destroyManager()` is called on a manager, it cannot be destroyed again (also note that all existing connections become inactive).',
  9. example: '===',
  10. required: true
  11. },
  12. meta: {
  13. friendlyName: 'Meta (custom)',
  14. description: 'Additional stuff to pass to the driver.',
  15. extendedDescription: 'This is reserved for custom driver-specific extensions. Please refer to the documentation for the driver you are using for more specific information.',
  16. example: '==='
  17. }
  18. },
  19. exits: {
  20. success: {
  21. description: 'The specified manager and all of its active connections were successfully destroyed.',
  22. outputVariableName: 'report',
  23. outputDescription: 'The `meta` property is reserved for custom driver-specific extensions.',
  24. outputExample: '==='
  25. // example: {
  26. // meta: '==='
  27. // }
  28. },
  29. failed: {
  30. friendlyName: 'Failed',
  31. description: 'Could not destroy the provided connection manager.',
  32. extendedDescription:
  33. 'Usually, this means the manager has already been destroyed. But depending on the driver ' +
  34. 'it could also mean that database cannot be accessed. In production, this can mean that the database ' +
  35. 'server(s) became overwhelemed or were shut off while some business logic was in progress.',
  36. outputVariableName: 'report',
  37. outputDescription: 'The `error` property is a JavaScript Error instance with more information and a stack trace. The `meta` property is reserved for custom driver-specific extensions.',
  38. outputExample: '==='
  39. // example: {
  40. // error: '===',
  41. // meta: '==='
  42. // }
  43. }
  44. },
  45. fn: function destroyManager(inputs, exits) {
  46. // Note that if this driver is adapted to support managers which spawn
  47. // ad-hoc connections or manage multiple pools/replicas using PoolCluster,
  48. // then relevant settings would need to be included in the manager instance
  49. // so that the manager could be appropriately destroyed here (in the case of
  50. // ad-hoc connections, leased connections would need to be tracked on the
  51. // manager, and then rounded up and disconnected here.)
  52. //
  53. // For now, since we only support a single pool, we simply destroy it.
  54. //
  55. // For more info, see:
  56. // • https://github.com/felixge/node-mysql/blob/v2.10.2/Readme.md#closing-all-the-connections-in-a-pool
  57. inputs.manager.pool.end(function end(err) {
  58. if (err) {
  59. return exits.failed({
  60. error: new Error('Failed to destroy the MySQL connection pool and/or gracefully end all connections in the pool. Details:\n=== === ===\n' + err.stack),
  61. meta: inputs.meta
  62. });
  63. }
  64. // All connections in the pool have ended.
  65. return exits.success({
  66. meta: inputs.meta
  67. });
  68. });
  69. }
  70. };