@sera4/essentia 1.0.26 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sera4/essentia",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "A library of utilities for Teleporte Web Services",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/package.tar.gz CHANGED
Binary file
package/queue/index.js CHANGED
@@ -16,6 +16,38 @@ class S4Queue {
16
16
  this.subs = {};
17
17
  }
18
18
 
19
+ /**
20
+ * Opens a connection and immediately closes it.
21
+ * To be used for health checks.
22
+ * @param {Object} options Connection parameters. At the very least options.connectionUrl must be present.
23
+ */
24
+ async testConnection(options) {
25
+ return new Promise((resolve, reject) => {
26
+ // We may run into issues with SNI TLS if
27
+ // we host with 3rd parties using our own certs.
28
+ // To avoid any issues, let's parse the url
29
+ // and provide the server name in the socket options
30
+ const urlParts = urlParse(options.connectionUrl);
31
+ const socketOptions = {servername: urlParts.hostname};
32
+
33
+ amqp.connect(options.connectionUrl, socketOptions, (err, conn) => {
34
+ if (err) {
35
+ return reject(err);
36
+ }
37
+ if (!conn) {
38
+ return reject("Failed to obtain connection");
39
+ }
40
+ conn.close(e => {
41
+ if (e) {
42
+ reject(e)
43
+ } else {
44
+ resolve(true)
45
+ }
46
+ })
47
+ });
48
+ });
49
+ }
50
+
19
51
  /**
20
52
  * Opens a connection to AMQP server.
21
53
  * @param {Object} options Connection parameters. At the very least options.connectionUrl must be present.