@sera4/essentia 1.0.30 → 1.0.32

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.
@@ -5,6 +5,22 @@ const colorizer = winston.format.colorize();
5
5
 
6
6
  require('winston-logstash');
7
7
 
8
+ // IETF RFC5424:
9
+ // Severity of all levels is assumed to be numerically ascending from most important to least important.
10
+ const levels = {
11
+ error: 0,
12
+ warn: 1,
13
+ info: 2,
14
+ debug: 3,
15
+ trace: 4,
16
+ }
17
+
18
+ // These colors are not used, however if colors are not defined for custom levels
19
+ // then winston will throw an exception.
20
+ winston.addColors({
21
+ trace: 'white'
22
+ })
23
+
8
24
  const devFormat = {
9
25
  transform(info) {
10
26
  const { message } = info;
@@ -17,10 +33,12 @@ const devFormat = {
17
33
  };
18
34
 
19
35
  const defaultTransport = new winston.transports.Console({
20
- format: devFormat
36
+ format: devFormat,
37
+ level: 'trace'
21
38
  });
22
39
 
23
40
  const logger = winston.createLogger({
41
+ levels: levels,
24
42
  level: 'debug',
25
43
  defaultMeta: { },
26
44
  transports: [defaultTransport]
@@ -32,9 +50,7 @@ class S4Logger {
32
50
  return;
33
51
  }
34
52
 
35
- if (options.level && ["debug", "info", "error", "warn"].indexOf(options.level.toLowerCase())) {
36
- logger.level = options.level;
37
- }
53
+ this.setLevel(options.level)
38
54
 
39
55
  logger.defaultMeta.service = options.service;
40
56
  switch(options.format.toLowerCase()) {
@@ -51,7 +67,7 @@ class S4Logger {
51
67
  }
52
68
 
53
69
  setLevel(level) {
54
- if (level && ["debug", "info", "error", "warn"].indexOf(level.toLowerCase())) {
70
+ if (level && ["trace", "debug", "info", "error", "warn"].indexOf(level.toLowerCase())) {
55
71
  logger.level = level;
56
72
  }
57
73
  }
@@ -68,6 +84,10 @@ class S4Logger {
68
84
  });
69
85
  }
70
86
 
87
+ trace(...args) {
88
+ logger.trace(util.format(...args));
89
+ }
90
+
71
91
  debug(...args) {
72
92
  logger.debug(util.format(...args));
73
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sera4/essentia",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
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
@@ -17,35 +17,27 @@ class S4Queue {
17
17
  }
18
18
 
19
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.
20
+ * Tests the connection to the service.
21
+ * Internally, the same connection is used for test
22
+ * and production code, but a separate channel is opened.
23
+ * Once the channel is obtained, there is an assert on the
24
+ * existence of a topic exchange called '--health-check--'.
25
+ * The following must be satisfied for the test to pass
26
+ * 1. must be connected
27
+ * 2. must have a test channel
28
+ * 3. must assert the exchange
23
29
  */
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};
30
+ async testConnection() {
31
+ if (!this.isConnected()) {
32
+ throw("queue service not connected")
33
+ }
32
34
 
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
- });
35
+ this.connectionTestChannel = this.connectionTestChannel || await this.connection.createChannel();
36
+ if (!this.connectionTestChannel) {
37
+ throw("queue service failed to obtain a channel")
38
+ }
39
+
40
+ await this.connectionTestChannel.assertExchange("--health-check--", "topic", {durable: false});
49
41
  }
50
42
 
51
43
  /**