@unchainedshop/core-worker 2.12.2 → 3.0.0-alpha2
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/director/WorkerDirector.d.ts.map +1 -1
- package/lib/director/WorkerDirector.js +0 -8
- package/lib/director/WorkerDirector.js.map +1 -1
- package/lib/director/WorkerEventTypes.d.ts +0 -1
- package/lib/director/WorkerEventTypes.d.ts.map +1 -1
- package/lib/director/WorkerEventTypes.js +0 -4
- package/lib/director/WorkerEventTypes.js.map +1 -1
- package/lib/module/configureWorkerModule.d.ts +9 -9
- package/package.json +7 -7
- package/src/director/WorkerDirector.ts +0 -10
- package/src/director/WorkerEventTypes.ts +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkerDirector.d.ts","sourceRoot":"","sources":["../../src/director/WorkerDirector.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAEhB,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"WorkerDirector.d.ts","sourceRoot":"","sources":["../../src/director/WorkerDirector.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EAEhB,MAAM,gCAAgC,CAAC;AAIxC,eAAO,MAAM,4BAA4B,2BAA2B,CAAC;AAQrE,eAAO,MAAM,cAAc,EAAE,eAgF5B,CAAC"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { log, LogLevel } from '@unchainedshop/logger';
|
|
2
2
|
import { BaseDirector } from '@unchainedshop/utils';
|
|
3
|
-
import { emit } from '@unchainedshop/events';
|
|
4
|
-
import { WorkerEventTypes } from './WorkerEventTypes.js';
|
|
5
3
|
export const DIRECTOR_MARKED_FAILED_ERROR = 'DIRECTOR_MARKED_FAILED';
|
|
6
4
|
const AutoScheduleMap = new Map();
|
|
7
5
|
const baseDirector = BaseDirector('WorkerDirector', {
|
|
@@ -60,7 +58,6 @@ export const WorkerDirector = {
|
|
|
60
58
|
}
|
|
61
59
|
try {
|
|
62
60
|
const output = await adapter.doWork(input, unchainedAPI, workId);
|
|
63
|
-
emit(WorkerEventTypes.DONE, { input, workId, output });
|
|
64
61
|
return output;
|
|
65
62
|
}
|
|
66
63
|
catch (error) {
|
|
@@ -68,11 +65,6 @@ export const WorkerDirector = {
|
|
|
68
65
|
log('DO not use this as flow control.', { level: LogLevel.Verbose });
|
|
69
66
|
log(`WorkerDirector -> Error doing work ${type}: ${error.message}`);
|
|
70
67
|
const errorOutput = { error, success: false };
|
|
71
|
-
emit(WorkerEventTypes.DONE, {
|
|
72
|
-
output: errorOutput,
|
|
73
|
-
input,
|
|
74
|
-
workId,
|
|
75
|
-
});
|
|
76
68
|
return errorOutput;
|
|
77
69
|
}
|
|
78
70
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkerDirector.js","sourceRoot":"","sources":["../../src/director/WorkerDirector.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"WorkerDirector.js","sourceRoot":"","sources":["../../src/director/WorkerDirector.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,CAAC,MAAM,4BAA4B,GAAG,wBAAwB,CAAC;AAErE,MAAM,eAAe,GAAG,IAAI,GAAG,EAAqC,CAAC;AAErE,MAAM,YAAY,GAAG,YAAY,CAA2B,gBAAgB,EAAE;IAC5E,eAAe,EAAE,KAAK;CACvB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,GAAG,YAAY;IAEf,oBAAoB,EAAE,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,EAAE;QAC1C,OAAO,c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AAO,KAAK,EAAE,CAAC;YACf,sGAAsG;YACtG,GAAG,CAAC,kCAAkC,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;YACrE,GAAG,CAAC,sCAAsC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAEpE,MAAM,WAAW,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;YAC9C,OAAO,WAAW,CAAC;QACrB,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkerEventTypes.d.ts","sourceRoot":"","sources":["../../src/director/WorkerEventTypes.ts"],"names":[],"mappings":"AAAA,oBAAY,gBAAgB;IAC1B,KAAK,eAAe;IACpB,SAAS,mBAAmB;IAC5B,
|
|
1
|
+
{"version":3,"file":"WorkerEventTypes.d.ts","sourceRoot":"","sources":["../../src/director/WorkerEventTypes.ts"],"names":[],"mappings":"AAAA,oBAAY,gBAAgB;IAC1B,KAAK,eAAe;IACpB,SAAS,mBAAmB;IAC5B,QAAQ,kBAAkB;IAC1B,OAAO,iBAAiB;IACxB,WAAW,qBAAqB;CACjC"}
|
|
@@ -2,12 +2,8 @@ export var WorkerEventTypes;
|
|
|
2
2
|
(function (WorkerEventTypes) {
|
|
3
3
|
WorkerEventTypes["ADDED"] = "WORK_ADDED";
|
|
4
4
|
WorkerEventTypes["ALLOCATED"] = "WORK_ALLOCATED";
|
|
5
|
-
WorkerEventTypes["DONE"] = "WORK_DONE";
|
|
6
5
|
WorkerEventTypes["FINISHED"] = "WORK_FINISHED";
|
|
7
6
|
WorkerEventTypes["DELETED"] = "WORK_DELETED";
|
|
8
7
|
WorkerEventTypes["RESCHEDULED"] = "WORK_RESCHEDULED";
|
|
9
8
|
})(WorkerEventTypes || (WorkerEventTypes = {}));
|
|
10
|
-
// The difference between `done` and `finished` is, that work is `done` after
|
|
11
|
-
// it was computed (no DB write, could be external) and `finished` after
|
|
12
|
-
// the changes are written to the DB
|
|
13
9
|
//# sourceMappingURL=WorkerEventTypes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkerEventTypes.js","sourceRoot":"","sources":["../../src/director/WorkerEventTypes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"WorkerEventTypes.js","sourceRoot":"","sources":["../../src/director/WorkerEventTypes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,wCAAoB,CAAA;IACpB,gDAA4B,CAAA;IAC5B,8CAA0B,CAAA;IAC1B,4CAAwB,CAAA;IACxB,oDAAgC,CAAA;AAClC,CAAC,EANW,gBAAgB,KAAhB,gBAAgB,QAM3B"}
|
|
@@ -17,21 +17,21 @@ export declare const buildQuerySelector: ({ created, scheduled, types, status, w
|
|
|
17
17
|
types?: Array<string>;
|
|
18
18
|
}) => {
|
|
19
19
|
[x: string]: any;
|
|
20
|
-
input?: mongodb.Condition<Record<string, any>>;
|
|
21
|
-
type?: mongodb.Condition<string>;
|
|
22
|
-
worker?: mongodb.Condition<string>;
|
|
23
20
|
error?: any;
|
|
24
21
|
timeout?: mongodb.Condition<number>;
|
|
25
|
-
result?: any;
|
|
26
|
-
started?: mongodb.Condition<Date>;
|
|
27
|
-
updated?: mongodb.Condition<Date>;
|
|
28
|
-
deleted?: mongodb.Condition<Date>;
|
|
29
|
-
originalWorkId?: mongodb.Condition<string>;
|
|
30
22
|
priority?: mongodb.Condition<number>;
|
|
31
23
|
retries?: mongodb.Condition<number>;
|
|
24
|
+
type?: mongodb.Condition<string>;
|
|
25
|
+
input?: mongodb.Condition<Record<string, any>>;
|
|
32
26
|
finished?: mongodb.Condition<Date>;
|
|
27
|
+
originalWorkId?: mongodb.Condition<string>;
|
|
28
|
+
result?: any;
|
|
29
|
+
started?: mongodb.Condition<Date>;
|
|
33
30
|
success?: mongodb.Condition<boolean>;
|
|
31
|
+
worker?: mongodb.Condition<string>;
|
|
34
32
|
autoscheduled?: mongodb.Condition<boolean>;
|
|
33
|
+
updated?: mongodb.Condition<Date>;
|
|
34
|
+
deleted?: mongodb.Condition<Date>;
|
|
35
35
|
_id?: mongodb.Condition<string>;
|
|
36
36
|
$and?: mongodb.Filter<mongodb.WithId<Work>>[];
|
|
37
37
|
$nor?: mongodb.Filter<mongodb.WithId<Work>>[];
|
|
@@ -44,8 +44,8 @@ export declare const buildQuerySelector: ({ created, scheduled, types, status, w
|
|
|
44
44
|
};
|
|
45
45
|
$where?: string | ((this: mongodb.WithId<Work>) => boolean);
|
|
46
46
|
$comment?: string | mongodb.BSON.Document;
|
|
47
|
-
created?: mongodb.Condition<Date>;
|
|
48
47
|
scheduled?: mongodb.Condition<Date>;
|
|
48
|
+
created?: mongodb.Condition<Date>;
|
|
49
49
|
};
|
|
50
50
|
export declare const configureWorkerModule: ({ db, options, }: ModuleInput<WorkerSettingsOptions>) => Promise<WorkerModule>;
|
|
51
51
|
//# sourceMappingURL=configureWorkerModule.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-worker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha2",
|
|
4
4
|
"main": "lib/worker-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/worker-index.js",
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@breejs/later": "^4.2.0",
|
|
35
|
-
"@unchainedshop/logger": "^
|
|
36
|
-
"@unchainedshop/utils": "^
|
|
35
|
+
"@unchainedshop/logger": "^3.0.0-alpha2",
|
|
36
|
+
"@unchainedshop/utils": "^3.0.0-alpha2",
|
|
37
37
|
"simpl-schema": "^3.4.6"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/node": "^20.14.
|
|
41
|
-
"@unchainedshop/types": "^
|
|
40
|
+
"@types/node": "^20.14.12",
|
|
41
|
+
"@unchainedshop/types": "^3.0.0-alpha2",
|
|
42
42
|
"jest": "^29.7.0",
|
|
43
|
-
"ts-jest": "^29.2.
|
|
44
|
-
"typescript": "^5.5.
|
|
43
|
+
"ts-jest": "^29.2.3",
|
|
44
|
+
"typescript": "^5.5.4"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -5,8 +5,6 @@ import {
|
|
|
5
5
|
} from '@unchainedshop/types/worker.js';
|
|
6
6
|
import { log, LogLevel } from '@unchainedshop/logger';
|
|
7
7
|
import { BaseDirector } from '@unchainedshop/utils';
|
|
8
|
-
import { emit } from '@unchainedshop/events';
|
|
9
|
-
import { WorkerEventTypes } from './WorkerEventTypes.js';
|
|
10
8
|
|
|
11
9
|
export const DIRECTOR_MARKED_FAILED_ERROR = 'DIRECTOR_MARKED_FAILED';
|
|
12
10
|
|
|
@@ -86,7 +84,6 @@ export const WorkerDirector: IWorkerDirector = {
|
|
|
86
84
|
|
|
87
85
|
try {
|
|
88
86
|
const output = await adapter.doWork(input, unchainedAPI, workId);
|
|
89
|
-
emit(WorkerEventTypes.DONE, { input, workId, output });
|
|
90
87
|
return output;
|
|
91
88
|
} catch (error) {
|
|
92
89
|
// DO not use this as flow control. The adapter should catch expected errors and return status: FAILED
|
|
@@ -94,13 +91,6 @@ export const WorkerDirector: IWorkerDirector = {
|
|
|
94
91
|
log(`WorkerDirector -> Error doing work ${type}: ${error.message}`);
|
|
95
92
|
|
|
96
93
|
const errorOutput = { error, success: false };
|
|
97
|
-
|
|
98
|
-
emit(WorkerEventTypes.DONE, {
|
|
99
|
-
output: errorOutput,
|
|
100
|
-
input,
|
|
101
|
-
workId,
|
|
102
|
-
});
|
|
103
|
-
|
|
104
94
|
return errorOutput;
|
|
105
95
|
}
|
|
106
96
|
},
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
export enum WorkerEventTypes {
|
|
2
2
|
ADDED = 'WORK_ADDED',
|
|
3
3
|
ALLOCATED = 'WORK_ALLOCATED',
|
|
4
|
-
DONE = 'WORK_DONE',
|
|
5
4
|
FINISHED = 'WORK_FINISHED',
|
|
6
5
|
DELETED = 'WORK_DELETED',
|
|
7
6
|
RESCHEDULED = 'WORK_RESCHEDULED',
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
// The difference between `done` and `finished` is, that work is `done` after
|
|
11
|
-
// it was computed (no DB write, could be external) and `finished` after
|
|
12
|
-
// the changes are written to the DB
|