navi-hey 0.5.0 → 0.5.2
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/README.md +1 -1
- package/lib/serializers/JobShowSerializer.js +22 -4
- package/lib/services/Client.js +6 -2
- package/lib/utils/logging/BaseLogger.js +14 -9
- package/lib/utils/logging/BufferedLogger.js +3 -2
- package/lib/utils/logging/ConsoleLogger.js +3 -2
- package/lib/utils/logging/Log.js +14 -2
- package/lib/utils/logging/LogBuffer.js +3 -2
- package/lib/utils/logging/LogFactory.js +3 -2
- package/lib/utils/logging/Logger.js +12 -8
- package/lib/utils/logging/LoggerGroup.js +12 -8
- package/package.json +1 -1
- package/static/assets/{index-sYKRvQgv.js → index-BF8_ow13.js} +6 -6
- package/static/index.html +1 -1
package/README.md
CHANGED
|
@@ -122,7 +122,7 @@ When the web server is enabled, the following screens are available:
|
|
|
122
122
|
| Dashboard | `/#/` | Real-time job queue stats (counts per status). |
|
|
123
123
|
| Jobs list | `/#/jobs` | Table of all jobs across every status, with links to individual job pages. |
|
|
124
124
|
| Job detail | `/#/job/:id` | Full details for a specific job (ID, status, attempt count). |
|
|
125
|
-
| `clients.<name>.base_url` | Base URL for the named HTTP client. |
|
|
125
|
+
| `clients.<name>.base_url` | Base URL for the named HTTP client. Supports environment variable references (`$VAR` or `${VAR}`), resolved at configuration load time. |
|
|
126
126
|
| `clients.<name>.headers` | Optional HTTP headers sent with every request of this client. Header values support environment variable references (`$VAR` or `${VAR}`), resolved at configuration load time. |
|
|
127
127
|
| `resources.<name>` | A named group of URL requests to warm. |
|
|
128
128
|
| `url` | URL path (appended to the client's `base_url`). Supports `{:placeholder}` tokens. |
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Serializer } from './Serializer.js';
|
|
2
2
|
|
|
3
|
+
const STATUSES_WITH_REMAINING_ATTEMPTS = new Set(['enqueued', 'processing', 'failed']);
|
|
4
|
+
const STATUSES_WITH_READY_IN_MS = new Set(['failed']);
|
|
5
|
+
const STATUSES_WITH_ERROR = new Set(['failed', 'dead']);
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* Serializes one or more job instances into show-view plain data objects.
|
|
5
9
|
* @augments Serializer
|
|
@@ -7,22 +11,36 @@ import { Serializer } from './Serializer.js';
|
|
|
7
11
|
class JobShowSerializer extends Serializer {
|
|
8
12
|
/**
|
|
9
13
|
* Serializes a single job instance into a full details object for the show view.
|
|
14
|
+
* Fields are included conditionally based on the job's status and recorded error.
|
|
10
15
|
*
|
|
11
16
|
* @param {object} job - A job instance.
|
|
12
17
|
* @param {object} options - Serialization options.
|
|
13
18
|
* @param {string} options.status - The status label to embed in the serialized object.
|
|
14
|
-
* @returns {
|
|
19
|
+
* @returns {object} The serialized job data with status-appropriate fields.
|
|
15
20
|
*/
|
|
16
21
|
static _serializeObject(job, { status }) {
|
|
17
|
-
|
|
22
|
+
const result = {
|
|
18
23
|
id: job.id,
|
|
19
24
|
status,
|
|
20
25
|
attempts: job._attempts,
|
|
21
26
|
jobClass: job.constructor.name,
|
|
22
27
|
arguments: job.arguments,
|
|
23
|
-
remainingAttempts: Math.max(0, job.maxRetries - job._attempts),
|
|
24
|
-
readyInMs: Math.max(0, job.readyBy - Date.now()),
|
|
25
28
|
};
|
|
29
|
+
|
|
30
|
+
if (STATUSES_WITH_REMAINING_ATTEMPTS.has(status)) {
|
|
31
|
+
result.remainingAttempts = Math.max(0, job.maxRetries - job._attempts);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (STATUSES_WITH_READY_IN_MS.has(status)) {
|
|
35
|
+
result.readyInMs = Math.max(0, job.readyBy - Date.now());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (STATUSES_WITH_ERROR.has(status) && job.lastError !== null && job.lastError !== undefined) {
|
|
39
|
+
result.lastError = job.lastError.message;
|
|
40
|
+
result.backtrace = job.lastError.stack;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return result;
|
|
26
44
|
}
|
|
27
45
|
}
|
|
28
46
|
|
package/lib/services/Client.js
CHANGED
|
@@ -30,7 +30,8 @@ class Client {
|
|
|
30
30
|
*
|
|
31
31
|
* @param {string} name The name identifying the client.
|
|
32
32
|
* @param {object} config Client configuration object.
|
|
33
|
-
* @param {string} config.base_url Base URL for the client.
|
|
33
|
+
* @param {string} config.base_url Base URL for the client. Values matching
|
|
34
|
+
* `$VAR` or `${VAR}` are resolved from `process.env` at parse time.
|
|
34
35
|
* @param {number} [config.timeout] Optional request timeout in milliseconds.
|
|
35
36
|
* @param {object} [config.headers] Optional HTTP headers. Values matching
|
|
36
37
|
* `$VAR` or `${VAR}` are resolved from `process.env` at parse time.
|
|
@@ -38,7 +39,8 @@ class Client {
|
|
|
38
39
|
*/
|
|
39
40
|
static fromObject(name, config) {
|
|
40
41
|
const headers = EnvResolver.resolveObject(config.headers || {});
|
|
41
|
-
|
|
42
|
+
const baseUrl = EnvResolver.resolveValue(config.base_url);
|
|
43
|
+
return new Client({ name, baseUrl, timeout: config.timeout, headers });
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
/**
|
|
@@ -110,6 +112,8 @@ class Client {
|
|
|
110
112
|
timeout: this.timeout,
|
|
111
113
|
responseType: 'text',
|
|
112
114
|
headers: this.headers,
|
|
115
|
+
maxRedirects: 0,
|
|
116
|
+
validateStatus: () => true,
|
|
113
117
|
});
|
|
114
118
|
|
|
115
119
|
if (response.status !== expectedStatus) {
|
|
@@ -20,44 +20,49 @@ class BaseLogger {
|
|
|
20
20
|
* Outputs a message at the given level. Override in subclasses.
|
|
21
21
|
* @param {string} _level - The log level.
|
|
22
22
|
* @param {string} _message - The message to output.
|
|
23
|
+
* @param {object} _attributes - The structured metadata for the log entry.
|
|
23
24
|
* @returns {void}
|
|
24
25
|
*/
|
|
25
|
-
_output(_level, _message) {}
|
|
26
|
+
_output(_level, _message, _attributes) {}
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Logs a debug message if the configured level allows it.
|
|
29
30
|
* @param {string} message - The message to log.
|
|
31
|
+
* @param {object} [attributes={}] - Optional structured metadata.
|
|
30
32
|
* @returns {void}
|
|
31
33
|
*/
|
|
32
|
-
debug(message) {
|
|
33
|
-
if (this.#shouldLog('debug')) this._output('debug', message);
|
|
34
|
+
debug(message, attributes = {}) {
|
|
35
|
+
if (this.#shouldLog('debug')) this._output('debug', message, attributes);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
/**
|
|
37
39
|
* Logs an info message if the configured level allows it.
|
|
38
40
|
* @param {string} message - The message to log.
|
|
41
|
+
* @param {object} [attributes={}] - Optional structured metadata.
|
|
39
42
|
* @returns {void}
|
|
40
43
|
*/
|
|
41
|
-
info(message) {
|
|
42
|
-
if (this.#shouldLog('info')) this._output('info', message);
|
|
44
|
+
info(message, attributes = {}) {
|
|
45
|
+
if (this.#shouldLog('info')) this._output('info', message, attributes);
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
/**
|
|
46
49
|
* Logs a warn message if the configured level allows it.
|
|
47
50
|
* @param {string} message - The message to log.
|
|
51
|
+
* @param {object} [attributes={}] - Optional structured metadata.
|
|
48
52
|
* @returns {void}
|
|
49
53
|
*/
|
|
50
|
-
warn(message) {
|
|
51
|
-
if (this.#shouldLog('warn')) this._output('warn', message);
|
|
54
|
+
warn(message, attributes = {}) {
|
|
55
|
+
if (this.#shouldLog('warn')) this._output('warn', message, attributes);
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
/**
|
|
55
59
|
* Logs an error message if the configured level allows it.
|
|
56
60
|
* @param {string} message - The message to log.
|
|
61
|
+
* @param {object} [attributes={}] - Optional structured metadata.
|
|
57
62
|
* @returns {void}
|
|
58
63
|
*/
|
|
59
|
-
error(message) {
|
|
60
|
-
if (this.#shouldLog('error')) this._output('error', message);
|
|
64
|
+
error(message, attributes = {}) {
|
|
65
|
+
if (this.#shouldLog('error')) this._output('error', message, attributes);
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
/**
|
|
@@ -23,10 +23,11 @@ class BufferedLogger extends BaseLogger {
|
|
|
23
23
|
* Stores the message in the buffer.
|
|
24
24
|
* @param {string} level - The log level ('debug', 'info', 'warn', 'error').
|
|
25
25
|
* @param {string} message - The message to output.
|
|
26
|
+
* @param {object} [attributes={}] - Optional structured metadata for the log entry.
|
|
26
27
|
* @returns {void}
|
|
27
28
|
*/
|
|
28
|
-
_output(level, message) {
|
|
29
|
-
this.#buffer.add(level, message);
|
|
29
|
+
_output(level, message, attributes = {}) {
|
|
30
|
+
this.#buffer.add(level, message, attributes);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
/**
|
|
@@ -9,10 +9,11 @@ class ConsoleLogger extends BaseLogger {
|
|
|
9
9
|
* Writes a message to the console at the given level.
|
|
10
10
|
* @param {string} level - One of 'debug', 'info', 'warn', 'error'.
|
|
11
11
|
* @param {string} message - The message to output.
|
|
12
|
+
* @param {object} [attributes={}] - Optional structured metadata to output alongside the message.
|
|
12
13
|
* @returns {void}
|
|
13
14
|
*/
|
|
14
|
-
_output(level, message) {
|
|
15
|
-
console[level](message); // eslint-disable-line no-console
|
|
15
|
+
_output(level, message, attributes = {}) {
|
|
16
|
+
console[level](message, attributes); // eslint-disable-line no-console
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
|
package/lib/utils/logging/Log.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Represents a single log entry with id, level, message and timestamp.
|
|
2
|
+
* Represents a single log entry with id, level, message, attributes and timestamp.
|
|
3
3
|
* @author darthjee
|
|
4
4
|
*/
|
|
5
5
|
class Log {
|
|
6
6
|
#id;
|
|
7
7
|
#level;
|
|
8
8
|
#message;
|
|
9
|
+
#attributes;
|
|
9
10
|
#timestamp;
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -13,11 +14,13 @@ class Log {
|
|
|
13
14
|
* @param {number} id - Unique incremental identifier for this log.
|
|
14
15
|
* @param {string} level - The log level (debug, info, warn, error).
|
|
15
16
|
* @param {string} message - The log message.
|
|
17
|
+
* @param {object} [attributes={}] - Optional structured metadata for the log entry.
|
|
16
18
|
*/
|
|
17
|
-
constructor(id, level, message) {
|
|
19
|
+
constructor(id, level, message, attributes = {}) {
|
|
18
20
|
this.#id = id;
|
|
19
21
|
this.#level = level;
|
|
20
22
|
this.#message = message;
|
|
23
|
+
this.#attributes = attributes;
|
|
21
24
|
this.#timestamp = new Date();
|
|
22
25
|
}
|
|
23
26
|
|
|
@@ -45,6 +48,14 @@ class Log {
|
|
|
45
48
|
return this.#message;
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Gets the log attributes.
|
|
53
|
+
* @returns {object} The structured metadata attached to this log entry.
|
|
54
|
+
*/
|
|
55
|
+
get attributes() {
|
|
56
|
+
return this.#attributes;
|
|
57
|
+
}
|
|
58
|
+
|
|
48
59
|
/**
|
|
49
60
|
* Gets the log timestamp.
|
|
50
61
|
* @returns {Date} The timestamp when the log was created.
|
|
@@ -62,6 +73,7 @@ class Log {
|
|
|
62
73
|
id: this.#id,
|
|
63
74
|
level: this.#level,
|
|
64
75
|
message: this.#message,
|
|
76
|
+
attributes: this.#attributes,
|
|
65
77
|
timestamp: this.#timestamp.toISOString()
|
|
66
78
|
};
|
|
67
79
|
}
|
|
@@ -25,10 +25,11 @@ class LogBuffer {
|
|
|
25
25
|
* If retention limit is reached, removes the oldest log.
|
|
26
26
|
* @param {string} level - The log level.
|
|
27
27
|
* @param {string} message - The log message.
|
|
28
|
+
* @param {object} [attributes={}] - Optional structured metadata for the log entry.
|
|
28
29
|
* @returns {import('./Log.js').Log} The created log entry.
|
|
29
30
|
*/
|
|
30
|
-
add(level, message) {
|
|
31
|
-
const log = this.#factory.build(level, message);
|
|
31
|
+
add(level, message, attributes = {}) {
|
|
32
|
+
const log = this.#factory.build(level, message, attributes);
|
|
32
33
|
|
|
33
34
|
this.#logs.push(log);
|
|
34
35
|
|
|
@@ -21,11 +21,12 @@ class LogFactory {
|
|
|
21
21
|
* Builds a new Log entry with an auto-assigned id.
|
|
22
22
|
* @param {string} level - The log level.
|
|
23
23
|
* @param {string} message - The log message.
|
|
24
|
+
* @param {object} [attributes={}] - Optional structured metadata for the log entry.
|
|
24
25
|
* @returns {Log} The created log entry.
|
|
25
26
|
*/
|
|
26
|
-
build(level, message) {
|
|
27
|
+
build(level, message, attributes = {}) {
|
|
27
28
|
const id = this.#idGenerator.generate();
|
|
28
|
-
return new Log(id, level, message);
|
|
29
|
+
return new Log(id, level, message, attributes);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -42,37 +42,41 @@ class Logger {
|
|
|
42
42
|
/**
|
|
43
43
|
* Logs a debug message using the default logger instance.
|
|
44
44
|
* @param {string} message - The message to log.
|
|
45
|
+
* @param {object} [attributes={}] - Optional structured metadata.
|
|
45
46
|
* @returns {void}
|
|
46
47
|
*/
|
|
47
|
-
static debug(message) {
|
|
48
|
-
this.default().debug(message);
|
|
48
|
+
static debug(message, attributes = {}) {
|
|
49
|
+
this.default().debug(message, attributes);
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/**
|
|
52
53
|
* Logs an info message using the default logger instance.
|
|
53
54
|
* @param {string} message - The message to log.
|
|
55
|
+
* @param {object} [attributes={}] - Optional structured metadata.
|
|
54
56
|
* @returns {void}
|
|
55
57
|
*/
|
|
56
|
-
static info(message) {
|
|
57
|
-
this.default().info(message);
|
|
58
|
+
static info(message, attributes = {}) {
|
|
59
|
+
this.default().info(message, attributes);
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
/**
|
|
61
63
|
* Logs a warn message using the default logger instance.
|
|
62
64
|
* @param {string} message - The message to log.
|
|
65
|
+
* @param {object} [attributes={}] - Optional structured metadata.
|
|
63
66
|
* @returns {void}
|
|
64
67
|
*/
|
|
65
|
-
static warn(message) {
|
|
66
|
-
this.default().warn(message);
|
|
68
|
+
static warn(message, attributes = {}) {
|
|
69
|
+
this.default().warn(message, attributes);
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
/**
|
|
70
73
|
* Logs an error message using the default logger instance.
|
|
71
74
|
* @param {string} message - The message to log.
|
|
75
|
+
* @param {object} [attributes={}] - Optional structured metadata.
|
|
72
76
|
* @returns {void}
|
|
73
77
|
*/
|
|
74
|
-
static error(message) {
|
|
75
|
-
this.default().error(message);
|
|
78
|
+
static error(message, attributes = {}) {
|
|
79
|
+
this.default().error(message, attributes);
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
/**
|
|
@@ -45,37 +45,41 @@ class LoggerGroup {
|
|
|
45
45
|
/**
|
|
46
46
|
* Broadcasts a debug message to all loggers in the group.
|
|
47
47
|
* @param {string} message - The message to log.
|
|
48
|
+
* @param {object} [attributes={}] - Optional structured metadata.
|
|
48
49
|
* @returns {void}
|
|
49
50
|
*/
|
|
50
|
-
debug(message) {
|
|
51
|
-
this.#loggers.forEach(logger => logger.debug(message));
|
|
51
|
+
debug(message, attributes = {}) {
|
|
52
|
+
this.#loggers.forEach(logger => logger.debug(message, attributes));
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Broadcasts an info message to all loggers in the group.
|
|
56
57
|
* @param {string} message - The message to log.
|
|
58
|
+
* @param {object} [attributes={}] - Optional structured metadata.
|
|
57
59
|
* @returns {void}
|
|
58
60
|
*/
|
|
59
|
-
info(message) {
|
|
60
|
-
this.#loggers.forEach(logger => logger.info(message));
|
|
61
|
+
info(message, attributes = {}) {
|
|
62
|
+
this.#loggers.forEach(logger => logger.info(message, attributes));
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
/**
|
|
64
66
|
* Broadcasts a warn message to all loggers in the group.
|
|
65
67
|
* @param {string} message - The message to log.
|
|
68
|
+
* @param {object} [attributes={}] - Optional structured metadata.
|
|
66
69
|
* @returns {void}
|
|
67
70
|
*/
|
|
68
|
-
warn(message) {
|
|
69
|
-
this.#loggers.forEach(logger => logger.warn(message));
|
|
71
|
+
warn(message, attributes = {}) {
|
|
72
|
+
this.#loggers.forEach(logger => logger.warn(message, attributes));
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
/**
|
|
73
76
|
* Broadcasts an error message to all loggers in the group.
|
|
74
77
|
* @param {string} message - The message to log.
|
|
78
|
+
* @param {object} [attributes={}] - Optional structured metadata.
|
|
75
79
|
* @returns {void}
|
|
76
80
|
*/
|
|
77
|
-
error(message) {
|
|
78
|
-
this.#loggers.forEach(logger => logger.error(message));
|
|
81
|
+
error(message, attributes = {}) {
|
|
82
|
+
this.#loggers.forEach(logger => logger.error(message, attributes));
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
/**
|