@event-driven-io/emmett-testcontainers 0.43.0-beta.4 → 0.43.0-beta.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/dist/index.cjs +45 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -20
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -35,29 +35,33 @@ var EmmettError = class _EmmettError extends Error {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
// ../emmett/dist/index.js
|
|
38
|
-
import { v4 as
|
|
38
|
+
import { v4 as uuid5 } from "uuid";
|
|
39
|
+
import { v7 as uuid2 } from "uuid";
|
|
39
40
|
import { v7 as uuid } from "uuid";
|
|
40
41
|
import retry from "async-retry";
|
|
41
|
-
import { v7 as
|
|
42
|
-
import { v4 as
|
|
43
|
-
import { v7 as
|
|
42
|
+
import { v7 as uuid3 } from "uuid";
|
|
43
|
+
import { v4 as uuid4 } from "uuid";
|
|
44
|
+
import { v7 as uuid6 } from "uuid";
|
|
44
45
|
var emmettPrefix = "emt";
|
|
45
46
|
var defaultTag = `${emmettPrefix}:default`;
|
|
46
47
|
var unknownTag = `${emmettPrefix}:unknown`;
|
|
47
48
|
var TaskProcessor = class {
|
|
48
|
-
constructor(options) {
|
|
49
|
-
this.options = options;
|
|
50
|
-
}
|
|
51
49
|
queue = [];
|
|
52
50
|
isProcessing = false;
|
|
53
51
|
activeTasks = 0;
|
|
54
52
|
activeGroups = /* @__PURE__ */ new Set();
|
|
53
|
+
options;
|
|
54
|
+
stopped = false;
|
|
55
|
+
constructor(options) {
|
|
56
|
+
this.options = options;
|
|
57
|
+
}
|
|
55
58
|
enqueue(task, options) {
|
|
59
|
+
if (this.stopped) {
|
|
60
|
+
return Promise.reject(new EmmettError("TaskProcessor has been stopped"));
|
|
61
|
+
}
|
|
56
62
|
if (this.queue.length >= this.options.maxQueueSize) {
|
|
57
63
|
return Promise.reject(
|
|
58
|
-
new EmmettError(
|
|
59
|
-
"Too many pending connections. Please try again later."
|
|
60
|
-
)
|
|
64
|
+
new EmmettError("Too many pending tasks. Please try again later.")
|
|
61
65
|
);
|
|
62
66
|
}
|
|
63
67
|
return this.schedule(task, options);
|
|
@@ -65,6 +69,15 @@ var TaskProcessor = class {
|
|
|
65
69
|
waitForEndOfProcessing() {
|
|
66
70
|
return this.schedule(({ ack }) => Promise.resolve(ack()));
|
|
67
71
|
}
|
|
72
|
+
async stop(options) {
|
|
73
|
+
if (this.stopped) return;
|
|
74
|
+
this.stopped = true;
|
|
75
|
+
this.queue.length = 0;
|
|
76
|
+
this.activeGroups.clear();
|
|
77
|
+
if (!options?.force) {
|
|
78
|
+
await this.waitForEndOfProcessing();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
68
81
|
schedule(task, options) {
|
|
69
82
|
return promiseWithDeadline(
|
|
70
83
|
(resolve, reject) => {
|
|
@@ -143,22 +156,33 @@ var DEFAULT_PROMISE_DEADLINE = 2147483647;
|
|
|
143
156
|
var promiseWithDeadline = (executor, options) => {
|
|
144
157
|
return new Promise((resolve, reject) => {
|
|
145
158
|
let taskStarted = false;
|
|
146
|
-
|
|
147
|
-
|
|
159
|
+
let timeoutId = null;
|
|
160
|
+
const deadline = options.deadline ?? DEFAULT_PROMISE_DEADLINE;
|
|
161
|
+
timeoutId = setTimeout(() => {
|
|
148
162
|
if (!taskStarted) {
|
|
149
163
|
reject(
|
|
150
164
|
new Error("Task was not started within the maximum waiting time")
|
|
151
165
|
);
|
|
152
166
|
}
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
167
|
+
}, deadline);
|
|
168
|
+
timeoutId.unref();
|
|
169
|
+
executor(
|
|
170
|
+
(value) => {
|
|
171
|
+
taskStarted = true;
|
|
172
|
+
if (timeoutId) {
|
|
173
|
+
clearTimeout(timeoutId);
|
|
174
|
+
}
|
|
175
|
+
timeoutId = null;
|
|
176
|
+
resolve(value);
|
|
177
|
+
},
|
|
178
|
+
(reason) => {
|
|
179
|
+
if (timeoutId) {
|
|
180
|
+
clearTimeout(timeoutId);
|
|
181
|
+
}
|
|
182
|
+
timeoutId = null;
|
|
183
|
+
reject(reason);
|
|
158
184
|
}
|
|
159
|
-
|
|
160
|
-
resolve(value);
|
|
161
|
-
}, reject);
|
|
185
|
+
);
|
|
162
186
|
});
|
|
163
187
|
};
|
|
164
188
|
var InProcessLock = () => {
|