@palmetto/pubsub 2.2.5 → 2.2.6
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 +4 -0
- package/dist/bullmq/publisher.js +11 -6
- package/dist/main.d.ts +1 -1
- package/dist/main.js +3 -1
- package/dist/publisher.js +15 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -114,6 +114,10 @@ yarn add @palmetto/pubsub zod
|
|
|
114
114
|
|
|
115
115
|
1. Register with dd-trace for improved trace logs
|
|
116
116
|
|
|
117
|
+
Datadog trace logs will include publisher and subscriber actions using the queue/job/exchange name.
|
|
118
|
+
|
|
119
|
+

|
|
120
|
+
|
|
117
121
|
```ts
|
|
118
122
|
import tracer from "dd-trace";
|
|
119
123
|
import { registerDdTrace } from "@palmetto/pubsub";
|
package/dist/bullmq/publisher.js
CHANGED
|
@@ -38,18 +38,23 @@ class BullMqPublisher {
|
|
|
38
38
|
}
|
|
39
39
|
publish(config, messages) {
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
var _a, _b;
|
|
41
42
|
const queue = yield this.getQueue(config);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
(_b = (_a = this.logger).debug) === null || _b === void 0 ? void 0 : _b.call(_a, `Publishing ${messages.length} messages to ${queue.name}`);
|
|
44
|
+
const job = {
|
|
45
|
+
name: config.job || connection_js_1.BULLMQ_DEFAULTJOB,
|
|
46
|
+
opts: {
|
|
46
47
|
attempts: config.retries,
|
|
47
48
|
backoff: {
|
|
48
49
|
type: "fixed",
|
|
49
50
|
delay: config.retryDelay || 30000,
|
|
50
51
|
},
|
|
51
|
-
}
|
|
52
|
-
}
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
const jobs = messages.map((data) => {
|
|
55
|
+
return Object.assign(Object.assign({}, job), { data });
|
|
56
|
+
});
|
|
57
|
+
yield queue.addBulk(jobs);
|
|
53
58
|
});
|
|
54
59
|
}
|
|
55
60
|
init(config) {
|
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -14,7 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
17
|
+
exports.registerDdTrace = void 0;
|
|
18
|
+
var dd_trace_wrapper_js_1 = require("./dd-trace.wrapper.js");
|
|
19
|
+
Object.defineProperty(exports, "registerDdTrace", { enumerable: true, get: function () { return dd_trace_wrapper_js_1.registerDdTrace; } });
|
|
18
20
|
__exportStar(require("./errors.js"), exports);
|
|
19
21
|
__exportStar(require("./interfaces.js"), exports);
|
|
20
22
|
__exportStar(require("./publisher.js"), exports);
|
package/dist/publisher.js
CHANGED
|
@@ -54,6 +54,9 @@ class Publisher {
|
|
|
54
54
|
}
|
|
55
55
|
publish(config, message) {
|
|
56
56
|
const messages = Array.isArray(message) ? message : [message];
|
|
57
|
+
if (messages.length === 0) {
|
|
58
|
+
return Promise.resolve();
|
|
59
|
+
}
|
|
57
60
|
return (0, dd_trace_wrapper_js_1.getTracer)().trace("pubsub.publish", {
|
|
58
61
|
resource: `publish ${config.transport} ${config.name}`,
|
|
59
62
|
}, (span) => {
|
|
@@ -64,7 +67,7 @@ class Publisher {
|
|
|
64
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
68
|
const provider = this.getProvider(config);
|
|
66
69
|
const { schema, schemaId } = this.assertSchema(config);
|
|
67
|
-
const
|
|
70
|
+
const mappedMessages = messages.map((msg) => {
|
|
68
71
|
if (!msg.id) {
|
|
69
72
|
msg.id = (0, uuid_1.v4)();
|
|
70
73
|
}
|
|
@@ -82,26 +85,32 @@ class Publisher {
|
|
|
82
85
|
if (!check.success) {
|
|
83
86
|
(0, message_logger_js_1.logMessage)({
|
|
84
87
|
note: "Publish message failed schema validation",
|
|
85
|
-
message:
|
|
88
|
+
message: msg,
|
|
86
89
|
level: "error",
|
|
87
90
|
logger: this.logger,
|
|
88
91
|
extra: Object.assign({ transport: provider.transport, name: config.name }, provider.enrichPublishedMesssageLog(config)),
|
|
89
92
|
});
|
|
90
|
-
|
|
93
|
+
return { json: JSON.stringify(msg), error: check.error };
|
|
91
94
|
}
|
|
92
95
|
const json = JSON.stringify(check.data);
|
|
93
96
|
return { json, data: check.data };
|
|
94
97
|
});
|
|
98
|
+
const errors = mappedMessages.filter((mm) => mm.error);
|
|
99
|
+
if (errors.length > 0) {
|
|
100
|
+
const errorMessage = errors.map((mm) => { var _a; return (_a = mm.error) === null || _a === void 0 ? void 0 : _a.message; }).join(", ");
|
|
101
|
+
throw new errors_js_1.SchemaValidationError(`Schema did not accept ${errors.length} of ${messages.length} message(s): ${errorMessage}`);
|
|
102
|
+
}
|
|
103
|
+
const jsons = mappedMessages.filter((j) => j.data).map((j) => j.json);
|
|
95
104
|
const start = (0, message_logger_js_1.startTiming)();
|
|
96
|
-
yield provider.publish(config, jsons
|
|
105
|
+
yield provider.publish(config, jsons);
|
|
97
106
|
const duration = (0, message_logger_js_1.getDuration)(start);
|
|
98
|
-
|
|
107
|
+
mappedMessages.forEach((msg) => {
|
|
99
108
|
(0, message_logger_js_1.logMessage)({
|
|
100
109
|
note: "Published message",
|
|
101
110
|
message: msg.data,
|
|
102
111
|
level: config.messageLogLevel,
|
|
103
112
|
logger: this.logger,
|
|
104
|
-
extra: Object.assign({ transport: provider.transport, name: config.name, durationMs: duration }, provider.enrichPublishedMesssageLog(config)),
|
|
113
|
+
extra: Object.assign({ transport: provider.transport, name: config.name, durationMs: duration, batchSize: messages.length }, provider.enrichPublishedMesssageLog(config)),
|
|
105
114
|
});
|
|
106
115
|
});
|
|
107
116
|
span.setTag("pubsub.duration_ms", duration);
|