@unchainedshop/core 4.0.0-rc.2 → 4.0.0-rc.3
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/lib/directors/BaseWorker.d.ts +3 -3
- package/lib/directors/BaseWorker.d.ts.map +1 -1
- package/lib/directors/BaseWorker.js +11 -11
- package/lib/directors/BaseWorker.js.map +1 -1
- package/lib/directors/EventListenerWorker.d.ts.map +1 -1
- package/lib/directors/EventListenerWorker.js +50 -18
- package/lib/directors/EventListenerWorker.js.map +1 -1
- package/lib/directors/FilterAdapter.d.ts +1 -1
- package/lib/directors/FilterAdapter.d.ts.map +1 -1
- package/lib/directors/IntervalWorker.d.ts.map +1 -1
- package/lib/directors/IntervalWorker.js +27 -9
- package/lib/directors/IntervalWorker.js.map +1 -1
- package/lib/services/searchProducts.d.ts.map +1 -1
- package/lib/services/searchProducts.js +1 -2
- package/lib/services/searchProducts.js.map +1 -1
- package/package.json +22 -22
- package/src/directors/BaseWorker.ts +13 -12
- package/src/directors/EventListenerWorker.ts +59 -19
- package/src/directors/FilterAdapter.ts +1 -1
- package/src/directors/IntervalWorker.ts +30 -9
- package/src/services/searchProducts.ts +1 -3
|
@@ -16,9 +16,9 @@ export interface IWorker<P extends {
|
|
|
16
16
|
maxWorkItemCount?: number;
|
|
17
17
|
referenceDate?: Date;
|
|
18
18
|
}) => Promise<void>;
|
|
19
|
-
reset: () => Promise<void
|
|
20
|
-
start: () => void;
|
|
21
|
-
stop: () => void;
|
|
19
|
+
reset: () => Promise<void> | void;
|
|
20
|
+
start: () => Promise<void> | void;
|
|
21
|
+
stop: () => Promise<void> | void;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
interface WorkerParams {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseWorker.d.ts","sourceRoot":"","sources":["../../src/directors/BaseWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAY,MAAM,4BAA4B,CA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B,EAAE,CAAC,OAAO,EAAE;YAAE,aAAa,EAAE,IAAI,CAAA;SAAE,KAAK,OAAO,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;QACpF,OAAO,EAAE,CAAC,OAAO,EAAE;YAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC;YAAC,aAAa,CAAC,EAAE,IAAI,CAAA;SAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QACzF,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QAClC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QAClC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;KAClC,CAAC;CACH;AAED,UAAU,YAAY;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;CACtB;AAED,eAAO,MAAM,UAAU,EAAE,OAAO,CAAC,YAAY,CAsF5C,CAAC"}
|
|
@@ -12,10 +12,10 @@ export const BaseWorker = {
|
|
|
12
12
|
},
|
|
13
13
|
actions: ({ workerId }, unchainedAPI) => {
|
|
14
14
|
const workerActions = {
|
|
15
|
-
start() {
|
|
15
|
+
async start() {
|
|
16
16
|
throw new Error(`Not implemented on ${this.constructor.key}`);
|
|
17
17
|
},
|
|
18
|
-
stop() {
|
|
18
|
+
async stop() {
|
|
19
19
|
throw new Error(`Not implemented on ${this.constructor.key}`);
|
|
20
20
|
},
|
|
21
21
|
reset: async (referenceDate = new Date()) => {
|
|
@@ -57,19 +57,19 @@ export const BaseWorker = {
|
|
|
57
57
|
return unchainedAPI.modules.worker.ensureOneWork(workData);
|
|
58
58
|
}));
|
|
59
59
|
},
|
|
60
|
-
process: async ({ maxWorkItemCount, referenceDate }) => {
|
|
60
|
+
process: async ({ maxWorkItemCount = 10, referenceDate }) => {
|
|
61
61
|
await workerActions.autorescheduleTypes({
|
|
62
62
|
referenceDate,
|
|
63
63
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
let processedCount = 0;
|
|
65
|
+
while (true) {
|
|
66
|
+
if (maxWorkItemCount && maxWorkItemCount <= processedCount)
|
|
67
|
+
break;
|
|
67
68
|
const doneWork = await WorkerDirector.processNextWork(unchainedAPI, workerId);
|
|
68
|
-
if (doneWork)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
await processRecursively();
|
|
69
|
+
if (!doneWork)
|
|
70
|
+
break;
|
|
71
|
+
processedCount++;
|
|
72
|
+
}
|
|
73
73
|
},
|
|
74
74
|
};
|
|
75
75
|
workerActions.reset();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseWorker.js","sourceRoot":"","sources":["../../src/directors/BaseWorker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,eAAe,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AA4BrD,MAAM,CAAC,MAAM,UAAU,GAA0B;IAC/C,GAAG,EAAE,4BAA4B;IACjC,KAAK,EAAE,wCAAwC;IAC/C,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,KAAK;IAEf,YAAY,EAAE,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,EAAE,EAAE;QAClC,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACnE,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAgB,EAAE,YAAY,EAAE,EAAE;QACpD,MAAM,aAAa,GAAG;YACpB,KAAK;
|
|
1
|
+
{"version":3,"file":"BaseWorker.js","sourceRoot":"","sources":["../../src/directors/BaseWorker.ts"],"names":[],"mappings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,QAAQ,CAAC,CAAC;gBAC7D,CAAC,CAAC,CACH,CAAC;YACJ,CAAC;YAED,OAAO,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE;gBAC1D,MAAM,aAAa,CAAC,mBAAmB,CAAC;oBACtC,aAAa;iBACd,CAAC,CAAC;gBAEH,IAAI,cAAc,GAAG,CAAC,CAAC;gBACvB,OAAO,IAAI,EAAE,CAAC;oBACZ,IAAI,gBAAgB,IAAI,gBAAgB,IAAI,cAAc;wBAAE,MAAM;oBAElE,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,eAAe,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;oBAC9E,IAAI,CAAC,QAAQ;wBAAE,MAAM;oBAErB,cAAc,EAAE,CAAC;gBACnB,CAAC;YACH,CAAC;SACF,CAAC;QAEF,aAAa,CAAC,KAAK,EAAE,CAAC;QAEtB,OAAO,aAAa,CAAC;IACvB,CAAC;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventListenerWorker.d.ts","sourceRoot":"","sources":["../../src/directors/EventListenerWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"EventListenerWorker.d.ts","sourceRoot":"","sources":["../../src/directors/EventListenerWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAkDtD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,mBAAmB,EAAE,OAAO,CAAC,yBAAyB,CA6ClE,CAAC"}
|
|
@@ -1,15 +1,42 @@
|
|
|
1
1
|
import { subscribe } from '@unchainedshop/events';
|
|
2
2
|
import { BaseWorker } from './BaseWorker.js';
|
|
3
3
|
import { WorkerEventTypes } from '@unchainedshop/core-worker';
|
|
4
|
+
import { setTimeout } from 'node:timers/promises';
|
|
5
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
6
|
+
const logger = createLogger('unchained:worker');
|
|
4
7
|
function debounce(func, wait) {
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
let abortController = null;
|
|
9
|
+
const debounced = (async (...args) => {
|
|
10
|
+
// Cancel any pending execution
|
|
11
|
+
if (abortController) {
|
|
12
|
+
abortController.abort();
|
|
13
|
+
}
|
|
14
|
+
// Create new abort controller for this execution
|
|
15
|
+
abortController = new AbortController();
|
|
16
|
+
try {
|
|
17
|
+
// Wait for the debounce period
|
|
18
|
+
await setTimeout(wait, undefined, { signal: abortController.signal });
|
|
19
|
+
// If we reach here, the timeout completed without being aborted
|
|
20
|
+
const result = await func(...args);
|
|
21
|
+
abortController = null;
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
// If the operation was aborted, don't execute the function
|
|
26
|
+
if (error.name === 'AbortError') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// Re-throw any other errors
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
debounced.cancel = () => {
|
|
34
|
+
if (abortController) {
|
|
35
|
+
abortController.abort();
|
|
36
|
+
abortController = null;
|
|
37
|
+
}
|
|
12
38
|
};
|
|
39
|
+
return debounced;
|
|
13
40
|
}
|
|
14
41
|
export const EventListenerWorker = {
|
|
15
42
|
...BaseWorker,
|
|
@@ -21,24 +48,29 @@ export const EventListenerWorker = {
|
|
|
21
48
|
const baseWorkerActions = BaseWorker.actions({ workerId, worker: EventListenerWorker }, unchainedAPI);
|
|
22
49
|
// Debounce in the event of many work queue events conflicting with each other
|
|
23
50
|
const processWorkQueue = debounce(async () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
51
|
+
try {
|
|
52
|
+
await baseWorkerActions.process({
|
|
53
|
+
maxWorkItemCount: 1, // only one work item at a time, else we could end up in a loop
|
|
54
|
+
referenceDate: EventListenerWorker.getFloorDate(),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
// Log error but don't crash the worker
|
|
59
|
+
logger.error(error);
|
|
60
|
+
}
|
|
28
61
|
}, 300);
|
|
29
62
|
return {
|
|
30
63
|
...baseWorkerActions,
|
|
31
|
-
start() {
|
|
64
|
+
async start() {
|
|
32
65
|
subscribe(WorkerEventTypes.ADDED, processWorkQueue);
|
|
33
66
|
subscribe(WorkerEventTypes.FINISHED, processWorkQueue);
|
|
34
|
-
setTimeout(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}, 300);
|
|
67
|
+
await setTimeout(300);
|
|
68
|
+
await baseWorkerActions.autorescheduleTypes({
|
|
69
|
+
referenceDate: EventListenerWorker.getFloorDate(),
|
|
70
|
+
});
|
|
39
71
|
},
|
|
40
72
|
stop() {
|
|
41
|
-
|
|
73
|
+
processWorkQueue.cancel();
|
|
42
74
|
},
|
|
43
75
|
};
|
|
44
76
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventListenerWorker.js","sourceRoot":"","sources":["../../src/directors/EventListenerWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAW,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"EventListenerWorker.js","sourceRoot":"","sources":["../../src/directors/EventListenerWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAW,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CA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|
29
|
-
productIds
|
|
29
|
+
productIds?: string[];
|
|
30
30
|
}, options: {
|
|
31
31
|
filterSelector: mongodb.Filter<Filter>;
|
|
32
32
|
productSelector: mongodb.Filter<Product>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilterAdapter.d.ts","sourceRoot":"","sources":["../../src/directors/FilterAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAe,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,mBAAmB,EAAE,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,MAAM,EAAE,CAAC;IAEpE,iBAAiB,EAAE,CACjB,MAAM,EAAE;QACN,aAAa,EAAE,MAAM,EAAE,CAAC;KACzB,EACD,OAAO,EAAE;QACP,cAAc,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACvC,kBAAkB,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC/C,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACvC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;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C;AAEF,eAAO,MAAM,aAAa,EAAE,IAAI,CAAC,cAAc,EAAE,KAAK,GAAG,OAAO,GAAG,SAAS,CAmC3E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntervalWorker.d.ts","sourceRoot":"","sources":["../../src/directors/IntervalWorker.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAc,OAAO,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"IntervalWorker.d.ts","sourceRoot":"","sources":["../../src/directors/IntervalWorker.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAc,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAOtD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAMD,eAAO,MAAM,kBAAkB,GAAI,UAAU,YAAY,WAWxD,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,oBAAoB,CA2CxD,CAAC"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import later from '@breejs/later';
|
|
2
2
|
import { BaseWorker } from './BaseWorker.js';
|
|
3
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
3
4
|
const { NODE_ENV } = process.env;
|
|
5
|
+
const logger = createLogger('unchained:worker');
|
|
4
6
|
const defaultSchedule = later.parse.text(NODE_ENV !== 'production' ? 'every 2 seconds' : 'every 30 seconds');
|
|
5
7
|
export const scheduleToInterval = (schedule) => {
|
|
6
8
|
const referenceDate = new Date(1000);
|
|
7
|
-
const
|
|
9
|
+
const nextDates = later.schedule(schedule).next(2, referenceDate);
|
|
10
|
+
if (!nextDates || nextDates.length < 2) {
|
|
11
|
+
throw new Error('Schedule must produce at least 2 consecutive dates');
|
|
12
|
+
}
|
|
13
|
+
const [one, two] = nextDates;
|
|
8
14
|
const diff = new Date(two).getTime() - new Date(one).getTime();
|
|
9
15
|
return Math.min(1000 * 60 * 60, diff); // at least once every hour!
|
|
10
16
|
};
|
|
@@ -14,22 +20,34 @@ export const IntervalWorker = {
|
|
|
14
20
|
label: 'Allocates work on fixed intervals with native node setInterval',
|
|
15
21
|
version: '1.0.0',
|
|
16
22
|
type: 'CRON',
|
|
17
|
-
actions: ({ workerId, batchCount =
|
|
23
|
+
actions: ({ workerId, batchCount = 10, schedule = defaultSchedule }, unchainedAPI) => {
|
|
18
24
|
const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker }, unchainedAPI);
|
|
19
25
|
const intervalDelay = scheduleToInterval(schedule);
|
|
20
|
-
let intervalHandle;
|
|
26
|
+
let intervalHandle = null;
|
|
21
27
|
return {
|
|
22
28
|
...baseWorkerActions,
|
|
23
29
|
start() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
// Prevent multiple intervals from running
|
|
31
|
+
if (intervalHandle) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
intervalHandle = setInterval(async () => {
|
|
35
|
+
try {
|
|
36
|
+
await baseWorkerActions.process({
|
|
37
|
+
maxWorkItemCount: batchCount,
|
|
38
|
+
referenceDate: IntervalWorker.getFloorDate(),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
logger.error(error);
|
|
43
|
+
}
|
|
29
44
|
}, intervalDelay);
|
|
30
45
|
},
|
|
31
46
|
stop() {
|
|
32
|
-
|
|
47
|
+
if (intervalHandle) {
|
|
48
|
+
clearInterval(intervalHandle);
|
|
49
|
+
intervalHandle = null;
|
|
50
|
+
}
|
|
33
51
|
},
|
|
34
52
|
};
|
|
35
53
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntervalWorker.js","sourceRoot":"","sources":["../../src/directors/IntervalWorker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAuB,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,UAAU,EAAW,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"IntervalWorker.js","sourceRoot":"","sources":["../../src/directors/IntervalWorker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAuB,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,UAAU,EAAW,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAEjC,MAAM,MAAM,GAAG,YAAY,CAAC,kBAAkB,CAAC,CAAC;AAQhD,MAAM,eAAe,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CACtC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,kBAAkB,CACnE,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAsB,EAAE,EAAE;IAC3D,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,aAAa,CAAW,CAAC;IAE5E,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;IAC7B,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;IAC/D,OAAO,IAAI,CAAC,GAAG,C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1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchProducts.d.ts","sourceRoot":"","sources":["../../src/services/searchProducts.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,mBAAmB,EACnB,WAAW,EACZ,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,WAAW,0BAA2B,SAAQ,mBAAmB;IACrE,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;CAC1C;AAED,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,WAAW,EACxB,EAAE,mBAAmB,EAAE,MAAM,EAAE,EAAE;IAAE,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;CAAE;;;;;
|
|
1
|
+
{"version":3,"file":"searchProducts.d.ts","sourceRoot":"","sources":["../../src/services/searchProducts.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,mBAAmB,EACnB,WAAW,EACZ,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,MAAM,WAAW,0BAA2B,SAAQ,mBAAmB;IACrE,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;CAC1C;AAED,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,WAAW,EACxB,EAAE,mBAAmB,EAAE,MAAM,EAAE,EAAE;IAAE,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;CAAE;;;;;GAqDxF"}
|
|
@@ -23,8 +23,7 @@ export async function searchProductsService(searchQuery, { forceLiveCollection,
|
|
|
23
23
|
totalProductIds: [],
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
const
|
|
27
|
-
const totalProductIds = (await filterActions.searchProducts({ productIds }, searchConfiguration)) || [];
|
|
26
|
+
const totalProductIds = (await filterActions.searchProducts(searchQuery, searchConfiguration)) || [];
|
|
28
27
|
const filteredProductIds = await FilterDirector.productFacetedSearch(totalProductIds, searchConfiguration, { modules: this });
|
|
29
28
|
const aggregatedTotalProductIds = filterActions.aggregateProductIds({
|
|
30
29
|
productIds: totalProductIds,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchProducts.js","sourceRoot":"","sources":["../../src/services/searchProducts.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,GAGjB,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAKvD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAEzC,WAAwB,EACxB,EAAE,mBAAmB,EAAE,MAAM,EAA0D;IAEvF,MAAM,aAAa,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAEvF,MAAM,cAAc,GAAG,MAAM,aAAa,CAAC,uBAAuB,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC,CAAC;IACvG,MAAM,eAAe,GAAG,MAAM,aAAa,CAAC,wBAAwB,CAClE,sBAAsB,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EACtD,EAAE,CACH,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC;IAExF,MAAM,mBAAmB,GAA+B;QACtD,WAAW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AAE,CAAC;QACzC,2CAA2C;QAC3C,sCAAsC;QACtC,OAAO;YACL,mBAAmB;YACnB,yBAAyB,EAAE,EAAE;YAC7B,4BAA4B,EAAE,EAAE;YAChC,eAAe,EAAE,EAAE;SACpB,CAAC;IACJ,CAAC;IAED,MAAM,eAAe,GAAG,CAAC,MAAM,aAAa,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC,IAAI,EAAE,CAAC;IAErG,MAAM,kBAAkB,GAAG,MAAM,cAAc,CAAC,oBAAoB,CAClE,eAAe,EACf,mBAAmB,EACnB,EAAE,OAAO,EAAE,IAAI,EAAE,CAClB,CAAC;IAEF,MAAM,yBAAyB,GAAG,aAAa,CAAC,mBAAmB,CAAC;QAClE,UAAU,EAAE,eAAe;KAC5B,CAAC,CAAC;IAEH,MAAM,4BAA4B,GAAG,aAAa,CAAC,mBAAmB,CAAC;QACrE,UAAU,EAAE,kBAAkB;KAC/B,CAAC,CAAC;IAEH,OAAO;QACL,mBAAmB;QACnB,eAAe;QACf,yBAAyB;QACzB,4BAA4B;KAC7B,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.3",
|
|
4
4
|
"main": "lib/core-index.js",
|
|
5
5
|
"types": "lib/core-index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -32,30 +32,30 @@
|
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@breejs/later": "^4.2.0",
|
|
35
|
-
"@unchainedshop/core-assortments": "^4.0.0-rc.
|
|
36
|
-
"@unchainedshop/core-bookmarks": "^4.0.0-rc.
|
|
37
|
-
"@unchainedshop/core-countries": "^4.0.0-rc.
|
|
38
|
-
"@unchainedshop/core-currencies": "^4.0.0-rc.
|
|
39
|
-
"@unchainedshop/core-delivery": "^4.0.0-rc.
|
|
40
|
-
"@unchainedshop/core-enrollments": "^4.0.0-rc.
|
|
41
|
-
"@unchainedshop/core-events": "^4.0.0-rc.
|
|
42
|
-
"@unchainedshop/core-files": "^4.0.0-rc.
|
|
43
|
-
"@unchainedshop/core-filters": "^4.0.0-rc.
|
|
44
|
-
"@unchainedshop/core-languages": "^4.0.0-rc.
|
|
45
|
-
"@unchainedshop/core-orders": "^4.0.0-rc.
|
|
46
|
-
"@unchainedshop/core-payment": "^4.0.0-rc.
|
|
47
|
-
"@unchainedshop/core-products": "^4.0.0-rc.
|
|
48
|
-
"@unchainedshop/core-quotations": "^4.0.0-rc.
|
|
49
|
-
"@unchainedshop/core-users": "^4.0.0-rc.
|
|
50
|
-
"@unchainedshop/core-warehousing": "^4.0.0-rc.
|
|
51
|
-
"@unchainedshop/core-worker": "^4.0.0-rc.
|
|
52
|
-
"@unchainedshop/logger": "^4.0.0-rc.
|
|
53
|
-
"@unchainedshop/utils": "^4.0.0-rc.
|
|
35
|
+
"@unchainedshop/core-assortments": "^4.0.0-rc.3",
|
|
36
|
+
"@unchainedshop/core-bookmarks": "^4.0.0-rc.3",
|
|
37
|
+
"@unchainedshop/core-countries": "^4.0.0-rc.3",
|
|
38
|
+
"@unchainedshop/core-currencies": "^4.0.0-rc.3",
|
|
39
|
+
"@unchainedshop/core-delivery": "^4.0.0-rc.3",
|
|
40
|
+
"@unchainedshop/core-enrollments": "^4.0.0-rc.3",
|
|
41
|
+
"@unchainedshop/core-events": "^4.0.0-rc.3",
|
|
42
|
+
"@unchainedshop/core-files": "^4.0.0-rc.3",
|
|
43
|
+
"@unchainedshop/core-filters": "^4.0.0-rc.3",
|
|
44
|
+
"@unchainedshop/core-languages": "^4.0.0-rc.3",
|
|
45
|
+
"@unchainedshop/core-orders": "^4.0.0-rc.3",
|
|
46
|
+
"@unchainedshop/core-payment": "^4.0.0-rc.3",
|
|
47
|
+
"@unchainedshop/core-products": "^4.0.0-rc.3",
|
|
48
|
+
"@unchainedshop/core-quotations": "^4.0.0-rc.3",
|
|
49
|
+
"@unchainedshop/core-users": "^4.0.0-rc.3",
|
|
50
|
+
"@unchainedshop/core-warehousing": "^4.0.0-rc.3",
|
|
51
|
+
"@unchainedshop/core-worker": "^4.0.0-rc.3",
|
|
52
|
+
"@unchainedshop/logger": "^4.0.0-rc.3",
|
|
53
|
+
"@unchainedshop/utils": "^4.0.0-rc.3"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/breejs__later": "^4.1.5",
|
|
57
|
-
"@types/node": "^
|
|
58
|
-
"tsx": "^4.
|
|
57
|
+
"@types/node": "^24.0.4",
|
|
58
|
+
"tsx": "^4.20.3",
|
|
59
59
|
"typescript": "^5.8.3"
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -17,9 +17,9 @@ export interface IWorker<P extends { workerId?: string }> {
|
|
|
17
17
|
) => {
|
|
18
18
|
autorescheduleTypes: (options: { referenceDate: Date }) => Promise<(Work | null)[]>;
|
|
19
19
|
process: (options: { maxWorkItemCount?: number; referenceDate?: Date }) => Promise<void>;
|
|
20
|
-
reset: () => Promise<void
|
|
21
|
-
start: () => void;
|
|
22
|
-
stop: () => void;
|
|
20
|
+
reset: () => Promise<void> | void;
|
|
21
|
+
start: () => Promise<void> | void;
|
|
22
|
+
stop: () => Promise<void> | void;
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -42,11 +42,11 @@ export const BaseWorker: IWorker<WorkerParams> = {
|
|
|
42
42
|
|
|
43
43
|
actions: ({ workerId }: WorkerParams, unchainedAPI) => {
|
|
44
44
|
const workerActions = {
|
|
45
|
-
start() {
|
|
45
|
+
async start() {
|
|
46
46
|
throw new Error(`Not implemented on ${this.constructor.key}`);
|
|
47
47
|
},
|
|
48
48
|
|
|
49
|
-
stop() {
|
|
49
|
+
async stop() {
|
|
50
50
|
throw new Error(`Not implemented on ${this.constructor.key}`);
|
|
51
51
|
},
|
|
52
52
|
|
|
@@ -93,19 +93,20 @@ export const BaseWorker: IWorker<WorkerParams> = {
|
|
|
93
93
|
);
|
|
94
94
|
},
|
|
95
95
|
|
|
96
|
-
process: async ({ maxWorkItemCount, referenceDate }) => {
|
|
96
|
+
process: async ({ maxWorkItemCount = 10, referenceDate }) => {
|
|
97
97
|
await workerActions.autorescheduleTypes({
|
|
98
98
|
referenceDate,
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
let processedCount = 0;
|
|
102
|
+
while (true) {
|
|
103
|
+
if (maxWorkItemCount && maxWorkItemCount <= processedCount) break;
|
|
104
|
+
|
|
103
105
|
const doneWork = await WorkerDirector.processNextWork(unchainedAPI, workerId);
|
|
104
|
-
if (doneWork)
|
|
105
|
-
return null;
|
|
106
|
-
};
|
|
106
|
+
if (!doneWork) break;
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
processedCount++;
|
|
109
|
+
}
|
|
109
110
|
},
|
|
110
111
|
};
|
|
111
112
|
|
|
@@ -1,16 +1,52 @@
|
|
|
1
1
|
import { subscribe } from '@unchainedshop/events';
|
|
2
2
|
import { BaseWorker, IWorker } from './BaseWorker.js';
|
|
3
3
|
import { WorkerEventTypes } from '@unchainedshop/core-worker';
|
|
4
|
+
import { setTimeout } from 'node:timers/promises';
|
|
5
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const logger = createLogger('unchained:worker');
|
|
8
|
+
|
|
9
|
+
function debounce<T extends (...args: any[]) => Promise<any>>(
|
|
10
|
+
func: T,
|
|
11
|
+
wait: number,
|
|
12
|
+
): T & { cancel: () => void } {
|
|
13
|
+
let abortController: AbortController | null = null;
|
|
14
|
+
|
|
15
|
+
const debounced = (async (...args: Parameters<T>) => {
|
|
16
|
+
// Cancel any pending execution
|
|
17
|
+
if (abortController) {
|
|
18
|
+
abortController.abort();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Create new abort controller for this execution
|
|
22
|
+
abortController = new AbortController();
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
// Wait for the debounce period
|
|
26
|
+
await setTimeout(wait, undefined, { signal: abortController.signal });
|
|
27
|
+
|
|
28
|
+
// If we reach here, the timeout completed without being aborted
|
|
29
|
+
const result = await func(...args);
|
|
30
|
+
abortController = null;
|
|
31
|
+
return result;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
// If the operation was aborted, don't execute the function
|
|
34
|
+
if (error.name === 'AbortError') {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// Re-throw any other errors
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}) as T & { cancel: () => void };
|
|
41
|
+
|
|
42
|
+
debounced.cancel = () => {
|
|
43
|
+
if (abortController) {
|
|
44
|
+
abortController.abort();
|
|
45
|
+
abortController = null;
|
|
46
|
+
}
|
|
13
47
|
};
|
|
48
|
+
|
|
49
|
+
return debounced;
|
|
14
50
|
}
|
|
15
51
|
|
|
16
52
|
export interface EventListenerWorkerParams {
|
|
@@ -33,28 +69,32 @@ export const EventListenerWorker: IWorker<EventListenerWorkerParams> = {
|
|
|
33
69
|
|
|
34
70
|
// Debounce in the event of many work queue events conflicting with each other
|
|
35
71
|
const processWorkQueue = debounce<() => Promise<void>>(async () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
72
|
+
try {
|
|
73
|
+
await baseWorkerActions.process({
|
|
74
|
+
maxWorkItemCount: 1, // only one work item at a time, else we could end up in a loop
|
|
75
|
+
referenceDate: EventListenerWorker.getFloorDate(),
|
|
76
|
+
});
|
|
77
|
+
} catch (error) {
|
|
78
|
+
// Log error but don't crash the worker
|
|
79
|
+
logger.error(error);
|
|
80
|
+
}
|
|
40
81
|
}, 300);
|
|
41
82
|
|
|
42
83
|
return {
|
|
43
84
|
...baseWorkerActions,
|
|
44
85
|
|
|
45
|
-
start() {
|
|
86
|
+
async start() {
|
|
46
87
|
subscribe(WorkerEventTypes.ADDED, processWorkQueue);
|
|
47
88
|
subscribe(WorkerEventTypes.FINISHED, processWorkQueue);
|
|
48
89
|
|
|
49
|
-
setTimeout(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, 300);
|
|
90
|
+
await setTimeout(300);
|
|
91
|
+
await baseWorkerActions.autorescheduleTypes({
|
|
92
|
+
referenceDate: EventListenerWorker.getFloorDate(),
|
|
93
|
+
});
|
|
54
94
|
},
|
|
55
95
|
|
|
56
96
|
stop() {
|
|
57
|
-
|
|
97
|
+
processWorkQueue.cancel();
|
|
58
98
|
},
|
|
59
99
|
};
|
|
60
100
|
},
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import later, { ScheduleData } from '@breejs/later';
|
|
2
2
|
import { BaseWorker, IWorker } from './BaseWorker.js';
|
|
3
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
3
4
|
|
|
4
5
|
const { NODE_ENV } = process.env;
|
|
5
6
|
|
|
7
|
+
const logger = createLogger('unchained:worker');
|
|
8
|
+
|
|
6
9
|
export interface IntervalWorkerParams {
|
|
7
10
|
workerId?: string;
|
|
8
11
|
batchCount?: number;
|
|
@@ -15,7 +18,13 @@ const defaultSchedule = later.parse.text(
|
|
|
15
18
|
|
|
16
19
|
export const scheduleToInterval = (schedule: ScheduleData) => {
|
|
17
20
|
const referenceDate = new Date(1000);
|
|
18
|
-
const
|
|
21
|
+
const nextDates = later.schedule(schedule).next(2, referenceDate) as Date[];
|
|
22
|
+
|
|
23
|
+
if (!nextDates || nextDates.length < 2) {
|
|
24
|
+
throw new Error('Schedule must produce at least 2 consecutive dates');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const [one, two] = nextDates;
|
|
19
28
|
const diff = new Date(two).getTime() - new Date(one).getTime();
|
|
20
29
|
return Math.min(1000 * 60 * 60, diff); // at least once every hour!
|
|
21
30
|
};
|
|
@@ -28,26 +37,38 @@ export const IntervalWorker: IWorker<IntervalWorkerParams> = {
|
|
|
28
37
|
version: '1.0.0',
|
|
29
38
|
type: 'CRON',
|
|
30
39
|
|
|
31
|
-
actions: ({ workerId, batchCount =
|
|
40
|
+
actions: ({ workerId, batchCount = 10, schedule = defaultSchedule }, unchainedAPI) => {
|
|
32
41
|
const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker }, unchainedAPI);
|
|
33
42
|
|
|
34
43
|
const intervalDelay = scheduleToInterval(schedule);
|
|
35
|
-
let intervalHandle: NodeJS.Timeout;
|
|
44
|
+
let intervalHandle: NodeJS.Timeout | null = null;
|
|
36
45
|
|
|
37
46
|
return {
|
|
38
47
|
...baseWorkerActions,
|
|
39
48
|
|
|
40
49
|
start() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
// Prevent multiple intervals from running
|
|
51
|
+
if (intervalHandle) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
intervalHandle = setInterval(async () => {
|
|
56
|
+
try {
|
|
57
|
+
await baseWorkerActions.process({
|
|
58
|
+
maxWorkItemCount: batchCount,
|
|
59
|
+
referenceDate: IntervalWorker.getFloorDate(),
|
|
60
|
+
});
|
|
61
|
+
} catch (error) {
|
|
62
|
+
logger.error(error);
|
|
63
|
+
}
|
|
46
64
|
}, intervalDelay);
|
|
47
65
|
},
|
|
48
66
|
|
|
49
67
|
stop() {
|
|
50
|
-
|
|
68
|
+
if (intervalHandle) {
|
|
69
|
+
clearInterval(intervalHandle);
|
|
70
|
+
intervalHandle = null;
|
|
71
|
+
}
|
|
51
72
|
},
|
|
52
73
|
};
|
|
53
74
|
},
|
|
@@ -47,9 +47,7 @@ export async function searchProductsService(
|
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
const
|
|
51
|
-
const totalProductIds =
|
|
52
|
-
(await filterActions.searchProducts({ productIds }, searchConfiguration)) || [];
|
|
50
|
+
const totalProductIds = (await filterActions.searchProducts(searchQuery, searchConfiguration)) || [];
|
|
53
51
|
|
|
54
52
|
const filteredProductIds = await FilterDirector.productFacetedSearch(
|
|
55
53
|
totalProductIds,
|