@unchainedshop/core-worker 2.0.0-beta7 → 2.0.0-beta9
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/jest.config.js +9 -0
- package/lib/director/WorkerDirector.js +2 -2
- package/lib/director/WorkerDirector.js.map +1 -1
- package/lib/module/configureWorkerModule.d.ts +18 -0
- package/lib/module/configureWorkerModule.js +18 -20
- package/lib/module/configureWorkerModule.js.map +1 -1
- package/lib/schedulers/FailedRescheduler.js +4 -4
- package/lib/schedulers/FailedRescheduler.js.map +1 -1
- package/lib/workers/BaseWorker.js +7 -7
- package/lib/workers/BaseWorker.js.map +1 -1
- package/lib/workers/EventListenerWorker.js +2 -2
- package/lib/workers/EventListenerWorker.js.map +1 -1
- package/lib/workers/IntervalWorker.js +2 -2
- package/lib/workers/IntervalWorker.js.map +1 -1
- package/package.json +9 -8
- package/src/director/WorkerDirector.ts +2 -3
- package/src/module/configureWorkerModule.ts +45 -60
- package/src/schedulers/FailedRescheduler.ts +10 -13
- package/src/workers/BaseWorker.ts +12 -16
- package/src/workers/EventListenerWorker.ts +2 -2
- package/src/workers/IntervalWorker.ts +2 -3
- package/tests/worker-index.test.ts +187 -31
package/jest.config.js
CHANGED
|
@@ -30,13 +30,13 @@ export const WorkerDirector = {
|
|
|
30
30
|
log(`WorkderDirector -> Configured ${adapter.type} ${adapter.key}@${adapter.version} (${adapter.label}) for Autorun at ${schedule}`);
|
|
31
31
|
},
|
|
32
32
|
getAutoSchedules: () => Array.from(AutoScheduleMap),
|
|
33
|
-
doWork: async ({ type, input, _id: workId },
|
|
33
|
+
doWork: async ({ type, input, _id: workId }, unchainedAPI) => {
|
|
34
34
|
const adapter = WorkerDirector.getAdapter(type);
|
|
35
35
|
if (!adapter) {
|
|
36
36
|
log(`WorkderDirector: No registered adapter for type: ${type}`);
|
|
37
37
|
}
|
|
38
38
|
try {
|
|
39
|
-
const output = await adapter.doWork(input,
|
|
39
|
+
const output = await adapter.doWork(input, unchainedAPI, workId);
|
|
40
40
|
WorkerDirector.events.emit(WorkerEventTypes.DONE, { output });
|
|
41
41
|
return output;
|
|
42
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkerDirector.js","sourceRoot":"","sources":["../../src/director/WorkerDirector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WorkerDirector.js","sourceRoot":"","sources":["../../src/director/WorkerDirector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,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,MAAM;CACxB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,GAAG,YAAY;IAEf,MAAM,EAAE,IAAI,YAAY,EAAE;IAE1B,oBAAoB,EAAE,CAAC,QAAQ,EAAE,EAAE;QACjC,OAAO,cAAc,CAAC,WAAW,EAAE;aAChC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;YAClB,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,SAAS;gBAAE,OAAO,IAAI,CAAC;YAC7D,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,QAAQ,CAAC;QAChD,CAAC,CAAC;aACD,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,eAAe,EAAE,CAAC,OAAO,EAAE,EAAE;QAC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YAErE,GAAG,CAAC,uCAAuC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YAErE,MAAM,WAAW,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;YAE9C,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE;gBAChD,MAAM,EAAE,WAAW;aACpB,CAAC,CAAC;YAEH,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;CACF,CAAC"}
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
import { Query } from '@unchainedshop/types/common';
|
|
1
2
|
import { ModuleInput } from '@unchainedshop/types/core';
|
|
2
3
|
import { WorkerModule } from '@unchainedshop/types/worker';
|
|
4
|
+
import { WorkStatus } from '../director/WorkStatus';
|
|
5
|
+
export declare const buildQuerySelector: ({ created, scheduled, types, status, workId, queryString, ...rest }: Query & {
|
|
6
|
+
created?: {
|
|
7
|
+
end?: Date;
|
|
8
|
+
start?: Date;
|
|
9
|
+
};
|
|
10
|
+
scheduled?: {
|
|
11
|
+
end?: Date;
|
|
12
|
+
start?: Date;
|
|
13
|
+
};
|
|
14
|
+
status?: Array<WorkStatus>;
|
|
15
|
+
workId?: string;
|
|
16
|
+
queryString?: string;
|
|
17
|
+
types?: Array<string>;
|
|
18
|
+
}) => {
|
|
19
|
+
[x: string]: any;
|
|
20
|
+
};
|
|
3
21
|
export declare const configureWorkerModule: ({ db, }: ModuleInput<Record<string, never>>) => Promise<WorkerModule>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import os from 'os';
|
|
1
2
|
import { log, LogLevel } from '@unchainedshop/logger';
|
|
2
3
|
import { generateDbFilterById, generateDbMutations, buildSortOptions } from '@unchainedshop/utils';
|
|
3
|
-
import os from 'os';
|
|
4
4
|
import { SortDirection } from '@unchainedshop/types/api';
|
|
5
5
|
import { WorkQueueCollection } from '../db/WorkQueueCollection';
|
|
6
6
|
import { WorkQueueSchema } from '../db/WorkQueueSchema';
|
|
@@ -8,7 +8,7 @@ import { DIRECTOR_MARKED_FAILED_ERROR, WorkerDirector } from '../director/Worker
|
|
|
8
8
|
import { WorkerEventTypes } from '../director/WorkerEventTypes';
|
|
9
9
|
import { WorkStatus } from '../director/WorkStatus';
|
|
10
10
|
const { UNCHAINED_WORKER_ID = os.hostname() } = process.env;
|
|
11
|
-
const buildQuerySelector = ({ created, scheduled, types, status, workId, queryString, ...rest }) => {
|
|
11
|
+
export const buildQuerySelector = ({ created, scheduled, types, status, workId, queryString, ...rest }) => {
|
|
12
12
|
const filterMap = {
|
|
13
13
|
[WorkStatus.DELETED]: { deleted: { $exists: true } },
|
|
14
14
|
[WorkStatus.NEW]: {
|
|
@@ -45,7 +45,7 @@ const buildQuerySelector = ({ created, scheduled, types, status, workId, querySt
|
|
|
45
45
|
? { $gte: scheduled.start || new Date(0), $lte: scheduled.end }
|
|
46
46
|
: { $gte: scheduled.start || new Date(0) };
|
|
47
47
|
}
|
|
48
|
-
if (types) {
|
|
48
|
+
if (types && Array.isArray(types)) {
|
|
49
49
|
query.type = { $in: types };
|
|
50
50
|
}
|
|
51
51
|
if (workId) {
|
|
@@ -64,7 +64,7 @@ const defaultSort = [
|
|
|
64
64
|
export const configureWorkerModule = async ({ db, }) => {
|
|
65
65
|
const WorkQueue = await WorkQueueCollection(db);
|
|
66
66
|
const mutations = generateDbMutations(WorkQueue, WorkQueueSchema);
|
|
67
|
-
const finishWork = async (workId, { error, finished = new Date(), result, started = new Date(), success, worker = UNCHAINED_WORKER_ID, }
|
|
67
|
+
const finishWork = async (workId, { error, finished = new Date(), result, started = new Date(), success, worker = UNCHAINED_WORKER_ID, }) => {
|
|
68
68
|
const workBeforeUpdate = await WorkQueue.findOne(buildQuerySelector({ workId, status: [WorkStatus.ALLOCATED] }));
|
|
69
69
|
if (!workBeforeUpdate)
|
|
70
70
|
return null;
|
|
@@ -77,13 +77,13 @@ export const configureWorkerModule = async ({ db, }) => {
|
|
|
77
77
|
...(!workBeforeUpdate.started ? { started } : {}),
|
|
78
78
|
worker,
|
|
79
79
|
},
|
|
80
|
-
}
|
|
80
|
+
});
|
|
81
81
|
const work = await WorkQueue.findOne(generateDbFilterById(workId), {});
|
|
82
82
|
log(`Finished work ${workId}`, {
|
|
83
83
|
level: LogLevel.Verbose,
|
|
84
84
|
work,
|
|
85
85
|
});
|
|
86
|
-
WorkerDirector.events.emit(WorkerEventTypes.FINISHED, { work
|
|
86
|
+
WorkerDirector.events.emit(WorkerEventTypes.FINISHED, { work });
|
|
87
87
|
return work;
|
|
88
88
|
};
|
|
89
89
|
return {
|
|
@@ -102,7 +102,7 @@ export const configureWorkerModule = async ({ db, }) => {
|
|
|
102
102
|
const workQueues = WorkQueue.find(selector, {
|
|
103
103
|
skip,
|
|
104
104
|
limit,
|
|
105
|
-
sort: buildSortOptions(sort),
|
|
105
|
+
sort: buildSortOptions(sort || defaultSort),
|
|
106
106
|
});
|
|
107
107
|
return workQueues.toArray();
|
|
108
108
|
},
|
|
@@ -140,7 +140,7 @@ export const configureWorkerModule = async ({ db, }) => {
|
|
|
140
140
|
throw new Error('Unexpected work status');
|
|
141
141
|
},
|
|
142
142
|
// Mutations
|
|
143
|
-
addWork: async ({ type, input, priority = 0, scheduled, originalWorkId, retries = 20 }
|
|
143
|
+
addWork: async ({ type, input, priority = 0, scheduled, originalWorkId, retries = 20 }) => {
|
|
144
144
|
if (!WorkerDirector.getAdapter(type)) {
|
|
145
145
|
throw new Error(`No plugin registered for type ${type}`);
|
|
146
146
|
}
|
|
@@ -153,12 +153,10 @@ export const configureWorkerModule = async ({ db, }) => {
|
|
|
153
153
|
originalWorkId,
|
|
154
154
|
retries,
|
|
155
155
|
created,
|
|
156
|
-
}, userId);
|
|
157
|
-
log(`WorkerDirector -> Work added ${workId} (${type} / ${new Date(scheduled || created).toISOString()} / ${retries})`, {
|
|
158
|
-
userId,
|
|
159
156
|
});
|
|
157
|
+
log(`WorkerDirector -> Work added ${workId} (${type} / ${new Date(scheduled || created).toISOString()} / ${retries})`);
|
|
160
158
|
const work = await WorkQueue.findOne(generateDbFilterById(workId), {});
|
|
161
|
-
WorkerDirector.events.emit(WorkerEventTypes.ADDED, { work
|
|
159
|
+
WorkerDirector.events.emit(WorkerEventTypes.ADDED, { work });
|
|
162
160
|
return work;
|
|
163
161
|
},
|
|
164
162
|
rescheduleWork: async (currentWork, scheduled) => {
|
|
@@ -234,29 +232,29 @@ export const configureWorkerModule = async ({ db, }) => {
|
|
|
234
232
|
return null;
|
|
235
233
|
}
|
|
236
234
|
},
|
|
237
|
-
doWork: (work,
|
|
238
|
-
return WorkerDirector.doWork(work,
|
|
235
|
+
doWork: (work, unchainedAPI) => {
|
|
236
|
+
return WorkerDirector.doWork(work, unchainedAPI);
|
|
239
237
|
},
|
|
240
238
|
finishWork,
|
|
241
|
-
deleteWork: async (workId
|
|
239
|
+
deleteWork: async (workId) => {
|
|
242
240
|
const workBeforeRemoval = await WorkQueue.findOne(buildQuerySelector({
|
|
243
241
|
workId,
|
|
244
242
|
status: [WorkStatus.NEW, WorkStatus.ALLOCATED],
|
|
245
243
|
}));
|
|
246
244
|
if (!workBeforeRemoval)
|
|
247
245
|
return null;
|
|
248
|
-
await mutations.delete(workId
|
|
246
|
+
await mutations.delete(workId);
|
|
249
247
|
const work = await WorkQueue.findOne(generateDbFilterById(workId), {});
|
|
250
|
-
WorkerDirector.events.emit(WorkerEventTypes.DELETED, { work
|
|
248
|
+
WorkerDirector.events.emit(WorkerEventTypes.DELETED, { work });
|
|
251
249
|
return work;
|
|
252
250
|
},
|
|
253
|
-
markOldWorkAsFailed: async ({ types, worker, referenceDate }
|
|
251
|
+
markOldWorkAsFailed: async ({ types, worker, referenceDate }) => {
|
|
254
252
|
const workQueue = await WorkQueue.find(buildQuerySelector({
|
|
255
253
|
status: [WorkStatus.ALLOCATED],
|
|
256
254
|
started: { $lte: referenceDate },
|
|
257
255
|
worker,
|
|
258
256
|
type: { $in: types },
|
|
259
|
-
}), {
|
|
257
|
+
}), { projection: { _id: true }, sort: { test: 1 } }).toArray();
|
|
260
258
|
return Promise.all(workQueue.map(({ _id }) => finishWork(_id, {
|
|
261
259
|
finished: new Date(),
|
|
262
260
|
result: null,
|
|
@@ -266,7 +264,7 @@ export const configureWorkerModule = async ({ db, }) => {
|
|
|
266
264
|
message: 'Director marked old work as failed after restart. This work was eventually running at the moment when node.js exited.',
|
|
267
265
|
},
|
|
268
266
|
worker,
|
|
269
|
-
}
|
|
267
|
+
})));
|
|
270
268
|
},
|
|
271
269
|
};
|
|
272
270
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureWorkerModule.js","sourceRoot":"","sources":["../../src/module/configureWorkerModule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC1F,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,MAAM,EAAE,mBAAmB,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAE5D,MAAM,kBAAkB,GAAG,CAAC,EAC1B,OAAO,EACP,SAAS,EACT,KAAK,EACL,MAAM,EACN,MAAM,EACN,WAAW,EACX,GAAG,IAAI,EAQR,EAAE,EAAE;IACH,MAAM,SAAS,GAAG;QAChB,CAAC,UAAU,C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,EAAE,CAAC;YAEZ,OAAO,OAAO,CAAC,GAAG,CAChB,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CACxB,UAAU,CACR,GAAa,EACb;gBACE,QAAQ,EAAE,IAAI,IAAI,EAAE;gBACpB,MAAM,EAAE,IAAI;gBACZ,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,4BAA4B;oBAClC,OAAO,EACL,uHAAuH;iBAC1H;gBACD,MAAM;aACP,EACD,MAAM,CACP,CACF,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"configureWorkerModule.js","sourceRoot":"","sources":["../../src/module/configureWorkerModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAIpB,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC1F,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,MAAM,EAAE,mBAAmB,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAE5D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EACjC,OAAO,EACP,SAAS,EACT,KAAK,EACL,MAAM,EACN,MAAM,EACN,WAAW,EACX,GAAG,IAAI,EAQR,EAAE,EAA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,CAAC;YAEZ,OAAO,OAAO,CAAC,GAAG,CAChB,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CACxB,UAAU,CAAC,GAAa,EAAE;gBACxB,QAAQ,EAAE,IAAI,IAAI,EAAE;gBACpB,MAAM,EAAE,IAAI;gBACZ,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,4BAA4B;oBAClC,OAAO,EACL,uHAAuH;iBAC1H;gBACD,MAAM;aACP,CAAC,CACH,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -5,8 +5,8 @@ export const FailedRescheduler = {
|
|
|
5
5
|
key: 'shop.unchained.scheduler.failed',
|
|
6
6
|
label: 'Reschedule failed works',
|
|
7
7
|
version: '1.0.0',
|
|
8
|
-
actions: (
|
|
9
|
-
const handleFinishedWork = ({ work
|
|
8
|
+
actions: (unchainedAPI) => {
|
|
9
|
+
const handleFinishedWork = ({ work }) => {
|
|
10
10
|
if (!work.success && work.retries > 0) {
|
|
11
11
|
const now = new Date();
|
|
12
12
|
const workDelayMs = work.scheduled.getTime() - work.created.getTime();
|
|
@@ -15,14 +15,14 @@ export const FailedRescheduler = {
|
|
|
15
15
|
? new Date(now.getTime() + workDelayMs * 2)
|
|
16
16
|
: new Date(now.setSeconds(now.getSeconds() + 5));
|
|
17
17
|
log(`${FailedRescheduler.key} -> Reschedule failed work ${work._id} ${work.type} for ${scheduled.toISOString()} (in ${Math.round(workDelayMs / 1000)}). Remaining retries: ${work.retries}`);
|
|
18
|
-
|
|
18
|
+
unchainedAPI.modules.worker.addWork({
|
|
19
19
|
type: work.type,
|
|
20
20
|
input: work.input,
|
|
21
21
|
priority: work.priority,
|
|
22
22
|
originalWorkId: work.originalWorkId || work._id,
|
|
23
23
|
retries: work.retries - 1,
|
|
24
24
|
scheduled,
|
|
25
|
-
}
|
|
25
|
+
});
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FailedRescheduler.js","sourceRoot":"","sources":["../../src/schedulers/FailedRescheduler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,MAAM,CAAC,MAAM,iBAAiB,GAAe;IAC3C,GAAG,EAAE,iCAAiC;IACtC,KAAK,EAAE,yBAAyB;IAChC,OAAO,EAAE,OAAO;IAEhB,OAAO,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"FailedRescheduler.js","sourceRoot":"","sources":["../../src/schedulers/FailedRescheduler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,MAAM,CAAC,MAAM,iBAAiB,GAAe;IAC3C,GAAG,EAAE,iCAAiC;IACtC,KAAK,EAAE,yBAAyB;IAChC,OAAO,EAAE,OAAO;IAEhB,OAAO,EAAE,CAAC,YAAY,EAAE,EAAE;QACxB,MAAM,kBAAkB,GAAG,CAAC,EAAE,IAAI,EAAkB,EAAE,EAAE;YACtD,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE;gBACrC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;gBACvB,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;gBAEtE,oEAAoE;gBACpE,MAAM,SAAS,GACb,WAAW,GAAG,IAAI;oBAChB,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,WAAW,GAAG,CAAC,CAAC;oBAC3C,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;gBAErD,GAAG,CACD,GAAG,iBAAiB,CAAC,GAAG,8BAA8B,IAAI,CAAC,GAAG,IAC5D,IAAI,CAAC,IACP,QAAQ,SAAS,CAAC,WAAW,EAAE,QAAQ,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,yBACnE,IAAI,CAAC,OACP,EAAE,CACH,CAAC;gBAEF,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;oBAClC,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,cAAc,EAAE,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,GAAG;oBAC/C,OAAO,EAAE,IAAI,CAAC,OAAO,GAAG,CAAC;oBACzB,SAAS;iBACV,CAAC,CAAC;aACJ;QACH,CAAC,CAAC;QAEF,OAAO;YACL,KAAK;gBACH,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;YAC1E,CAAC;YAED,IAAI;gBACF,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;YAC3E,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -14,7 +14,7 @@ export const BaseWorker = {
|
|
|
14
14
|
const floored = new Date(Math.floor(date.getTime() / 1000) * 1000);
|
|
15
15
|
return floored;
|
|
16
16
|
},
|
|
17
|
-
actions: ({ workerId, worker },
|
|
17
|
+
actions: ({ workerId, worker }, unchainedAPI) => {
|
|
18
18
|
const resolvedWorkerId = resolveWorkerId(workerId, worker.type);
|
|
19
19
|
log(`${worker.key} -> Initialized: ${resolvedWorkerId}`);
|
|
20
20
|
const workerActions = {
|
|
@@ -25,7 +25,7 @@ export const BaseWorker = {
|
|
|
25
25
|
throw new Error(`Not implemented on ${this.constructor.key}`);
|
|
26
26
|
},
|
|
27
27
|
reset: async (referenceDate = new Date()) => {
|
|
28
|
-
await
|
|
28
|
+
await unchainedAPI.modules.worker.markOldWorkAsFailed({
|
|
29
29
|
types: WorkerDirector.getActivePluginTypes(false),
|
|
30
30
|
worker: workerId,
|
|
31
31
|
referenceDate,
|
|
@@ -38,7 +38,7 @@ export const BaseWorker = {
|
|
|
38
38
|
fixedSchedule.schedules[0].s = [0]; // ignore seconds, always run on second 0
|
|
39
39
|
const nextDate = later.schedule(fixedSchedule).next(1, referenceDate);
|
|
40
40
|
nextDate.setMilliseconds(0);
|
|
41
|
-
return
|
|
41
|
+
return unchainedAPI.modules.worker.ensureOneWork({
|
|
42
42
|
type,
|
|
43
43
|
input: input(),
|
|
44
44
|
scheduled: nextDate,
|
|
@@ -56,19 +56,19 @@ export const BaseWorker = {
|
|
|
56
56
|
const processRecursively = async (recursionCounter = 0) => {
|
|
57
57
|
if (maxWorkItemCount && maxWorkItemCount < recursionCounter)
|
|
58
58
|
return null;
|
|
59
|
-
const work = await
|
|
59
|
+
const work = await unchainedAPI.modules.worker.allocateWork({
|
|
60
60
|
types: WorkerDirector.getActivePluginTypes(false),
|
|
61
61
|
worker: workerId,
|
|
62
62
|
});
|
|
63
63
|
let doneWork = null;
|
|
64
64
|
if (work) {
|
|
65
|
-
const output = await
|
|
66
|
-
doneWork = await
|
|
65
|
+
const output = await unchainedAPI.modules.worker.doWork(work, unchainedAPI);
|
|
66
|
+
doneWork = await unchainedAPI.modules.worker.finishWork(work._id, {
|
|
67
67
|
...output,
|
|
68
68
|
finished: work.finished || new Date(),
|
|
69
69
|
started: work.started,
|
|
70
70
|
worker: workerId,
|
|
71
|
-
}
|
|
71
|
+
});
|
|
72
72
|
}
|
|
73
73
|
if (doneWork)
|
|
74
74
|
return processRecursively(recursionCounter + 1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseWorker.js","sourceRoot":"","sources":["../../src/workers/BaseWorker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAE5C,MAAM,eAAe,GAAG,CAAC,cAAsB,EAAE,IAAY,EAAE,EAAE,CAC/D,cAAc,IAAI,mBAAmB,IAAI,GAAG,EAAE,CAAC,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC;AAOtE,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,EAAE,MAAM,EAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"BaseWorker.js","sourceRoot":"","sources":["../../src/workers/BaseWorker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,MAAM,IAAI,CAAC;A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AC,CAAC;gBAEH,MAAM,kBAAkB,GAAG,KAAK,EAAE,gBAAgB,GAAG,CAAC,EAAE,EAAE;oBACxD,IAAI,gBAAgB,IAAI,gBAAgB,GAAG,gBAAgB;wBAAE,OAAO,IAAI,CAAC;oBAEzE,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;wBAC1D,KAAK,EAAE,cAAc,CAAC,oBAAoB,CAAC,KAAK,CAAC;wBACjD,MAAM,EAAE,QAAQ;qBACjB,CAAC,CAAC;oBAEH,IAAI,QAAQ,GAAgB,IAAI,CAAC;oBAEjC,IAAI,IAAI,EAAE;wBACR,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;wBAE5E,QAAQ,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE;4BAChE,GAAG,MAAM;4BACT,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,IAAI,IAAI,EAAE;4BACrC,OAAO,EAAE,IAAI,CAAC,OAAO;4BACrB,MAAM,EAAE,QAAQ;yBACjB,CAAC,CAAC;qBACJ;oBAED,IAAI,QAAQ;wBAAE,OAAO,kBAAkB,CAAC,gBAAgB,GAAG,CAAC,CAAC,CAAC;oBAE9D,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC;gBAEF,MAAM,kBAAkB,EAAE,CAAC;YAC7B,CAAC;SACF,CAAC;QAEF,aAAa,CAAC,KAAK,EAAE,CAAC;QAEtB,OAAO,aAAa,CAAC;IACvB,CAAC;CACF,CAAC"}
|
|
@@ -7,10 +7,10 @@ export const EventListenerWorker = {
|
|
|
7
7
|
label: 'Allocates work on events. This worker does not make sense on multiple containers.',
|
|
8
8
|
version: '1.0.0',
|
|
9
9
|
type: 'EVENT_LISTENER',
|
|
10
|
-
actions: ({ workerId },
|
|
10
|
+
actions: ({ workerId }, unchainedAPI) => {
|
|
11
11
|
let onAdded;
|
|
12
12
|
let onFinished;
|
|
13
|
-
const baseWorkerActions = BaseWorker.actions({ workerId, worker: EventListenerWorker },
|
|
13
|
+
const baseWorkerActions = BaseWorker.actions({ workerId, worker: EventListenerWorker }, unchainedAPI);
|
|
14
14
|
return {
|
|
15
15
|
...baseWorkerActions,
|
|
16
16
|
start() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventListenerWorker.js","sourceRoot":"","sources":["../../src/workers/EventListenerWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,MAAM,mBAAmB,GAAkC;IAChE,GAAG,UAAU;IAEb,GAAG,EAAE,sCAAsC;IAC3C,KAAK,EAAE,mFAAmF;IAC1F,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,gBAAgB;IAEtB,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"EventListenerWorker.js","sourceRoot":"","sources":["../../src/workers/EventListenerWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,MAAM,mBAAmB,GAAkC;IAChE,GAAG,UAAU;IAEb,GAAG,EAAE,sCAAsC;IAC3C,KAAK,EAAE,mFAAmF;IAC1F,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,gBAAgB;IAEtB,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,YAAY,EAAE,EAAE;QACtC,IAAI,OAA4B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
label: 'Allocates work on fixed intervals with native node setInterval',
|
|
16
16
|
version: '1.0.0',
|
|
17
17
|
type: 'CRON',
|
|
18
|
-
actions: ({ workerId, batchCount = 0, schedule = defaultSchedule },
|
|
19
|
-
const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker },
|
|
18
|
+
actions: ({ workerId, batchCount = 0, schedule = defaultSchedule }, unchainedAPI) => {
|
|
19
|
+
const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker }, unchainedAPI);
|
|
20
20
|
const intervalDelay = scheduleToInterval(schedule);
|
|
21
21
|
let intervalHandle;
|
|
22
22
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntervalWorker.js","sourceRoot":"","sources":["../../src/workers/IntervalWorker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IntervalWorker.js","sourceRoot":"","sources":["../../src/workers/IntervalWorker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAQjC,MAAM,eAAe,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CACtC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,kBAAkB,CACjD,CAAC;AAEpB,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,WAAoC,EAAE,EAAE;IACzE,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,QAAQ,GAAG,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;IAC/F,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,QAAQ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ker",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta9",
|
|
4
4
|
"main": "lib/worker-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/worker-index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"clean": "rm -rf lib",
|
|
13
13
|
"build": "npm run clean && tsc",
|
|
14
14
|
"watch": "tsc -w",
|
|
15
|
-
"test": "jest --
|
|
15
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
|
|
16
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
|
|
16
17
|
},
|
|
17
18
|
"repository": {
|
|
18
19
|
"type": "git",
|
|
@@ -31,15 +32,15 @@
|
|
|
31
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
32
33
|
"dependencies": {
|
|
33
34
|
"@breejs/later": "^4.1.0",
|
|
34
|
-
"@unchainedshop/logger": "^2.0.0-
|
|
35
|
-
"@unchainedshop/utils": "^2.0.0-
|
|
36
|
-
"simpl-schema": "^3.0
|
|
35
|
+
"@unchainedshop/logger": "^2.0.0-beta9",
|
|
36
|
+
"@unchainedshop/utils": "^2.0.0-beta9",
|
|
37
|
+
"simpl-schema": "^3.2.0"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^18.11.
|
|
40
|
-
"@unchainedshop/types": "^2.0.0-
|
|
40
|
+
"@types/node": "^18.11.12",
|
|
41
|
+
"@unchainedshop/types": "^2.0.0-beta9",
|
|
41
42
|
"jest": "^29.3.1",
|
|
42
43
|
"ts-jest": "^29.0.3",
|
|
43
|
-
"typescript": "^4.
|
|
44
|
+
"typescript": "^4.9.4"
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Context } from '@unchainedshop/types/api';
|
|
2
1
|
import { IWorkerAdapter, IWorkerDirector, WorkScheduleConfiguration } from '@unchainedshop/types/worker';
|
|
3
2
|
import { EventEmitter } from 'events';
|
|
4
3
|
import { log, LogLevel } from '@unchainedshop/logger';
|
|
@@ -45,7 +44,7 @@ export const WorkerDirector: IWorkerDirector = {
|
|
|
45
44
|
},
|
|
46
45
|
getAutoSchedules: () => Array.from(AutoScheduleMap),
|
|
47
46
|
|
|
48
|
-
doWork: async ({ type, input, _id: workId },
|
|
47
|
+
doWork: async ({ type, input, _id: workId }, unchainedAPI) => {
|
|
49
48
|
const adapter = WorkerDirector.getAdapter(type);
|
|
50
49
|
|
|
51
50
|
if (!adapter) {
|
|
@@ -53,7 +52,7 @@ export const WorkerDirector: IWorkerDirector = {
|
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
try {
|
|
56
|
-
const output = await adapter.doWork(input,
|
|
55
|
+
const output = await adapter.doWork(input, unchainedAPI, workId);
|
|
57
56
|
WorkerDirector.events.emit(WorkerEventTypes.DONE, { output });
|
|
58
57
|
return output;
|
|
59
58
|
} catch (error) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import { Query } from '@unchainedshop/types/common';
|
|
2
3
|
import { ModuleInput, ModuleMutations } from '@unchainedshop/types/core';
|
|
3
4
|
import { Work, WorkerModule } from '@unchainedshop/types/worker';
|
|
4
5
|
import { log, LogLevel } from '@unchainedshop/logger';
|
|
5
6
|
import { generateDbFilterById, generateDbMutations, buildSortOptions } from '@unchainedshop/utils';
|
|
6
|
-
import os from 'os';
|
|
7
7
|
import { SortDirection } from '@unchainedshop/types/api';
|
|
8
8
|
import { WorkQueueCollection } from '../db/WorkQueueCollection';
|
|
9
9
|
import { WorkQueueSchema } from '../db/WorkQueueSchema';
|
|
@@ -13,7 +13,7 @@ import { WorkStatus } from '../director/WorkStatus';
|
|
|
13
13
|
|
|
14
14
|
const { UNCHAINED_WORKER_ID = os.hostname() } = process.env;
|
|
15
15
|
|
|
16
|
-
const buildQuerySelector = ({
|
|
16
|
+
export const buildQuerySelector = ({
|
|
17
17
|
created,
|
|
18
18
|
scheduled,
|
|
19
19
|
types,
|
|
@@ -70,7 +70,7 @@ const buildQuerySelector = ({
|
|
|
70
70
|
? { $gte: scheduled.start || new Date(0), $lte: scheduled.end }
|
|
71
71
|
: { $gte: scheduled.start || new Date(0) };
|
|
72
72
|
}
|
|
73
|
-
if (types) {
|
|
73
|
+
if (types && Array.isArray(types)) {
|
|
74
74
|
query.type = { $in: types };
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -106,7 +106,6 @@ export const configureWorkerModule = async ({
|
|
|
106
106
|
success,
|
|
107
107
|
worker = UNCHAINED_WORKER_ID,
|
|
108
108
|
},
|
|
109
|
-
userId,
|
|
110
109
|
) => {
|
|
111
110
|
const workBeforeUpdate = await WorkQueue.findOne(
|
|
112
111
|
buildQuerySelector({ workId, status: [WorkStatus.ALLOCATED] }),
|
|
@@ -114,20 +113,16 @@ export const configureWorkerModule = async ({
|
|
|
114
113
|
|
|
115
114
|
if (!workBeforeUpdate) return null;
|
|
116
115
|
|
|
117
|
-
await mutations.update(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
...(!workBeforeUpdate.started ? { started } : {}),
|
|
126
|
-
worker,
|
|
127
|
-
},
|
|
116
|
+
await mutations.update(workId, {
|
|
117
|
+
$set: {
|
|
118
|
+
finished,
|
|
119
|
+
success,
|
|
120
|
+
error,
|
|
121
|
+
result,
|
|
122
|
+
...(!workBeforeUpdate.started ? { started } : {}),
|
|
123
|
+
worker,
|
|
128
124
|
},
|
|
129
|
-
|
|
130
|
-
);
|
|
125
|
+
});
|
|
131
126
|
|
|
132
127
|
const work = await WorkQueue.findOne(generateDbFilterById(workId), {});
|
|
133
128
|
|
|
@@ -136,7 +131,7 @@ export const configureWorkerModule = async ({
|
|
|
136
131
|
work,
|
|
137
132
|
});
|
|
138
133
|
|
|
139
|
-
WorkerDirector.events.emit(WorkerEventTypes.FINISHED, { work
|
|
134
|
+
WorkerDirector.events.emit(WorkerEventTypes.FINISHED, { work });
|
|
140
135
|
|
|
141
136
|
return work;
|
|
142
137
|
};
|
|
@@ -160,7 +155,7 @@ export const configureWorkerModule = async ({
|
|
|
160
155
|
const workQueues = WorkQueue.find(selector, {
|
|
161
156
|
skip,
|
|
162
157
|
limit,
|
|
163
|
-
sort: buildSortOptions(sort
|
|
158
|
+
sort: buildSortOptions(sort || defaultSort),
|
|
164
159
|
});
|
|
165
160
|
|
|
166
161
|
return workQueues.toArray();
|
|
@@ -210,37 +205,31 @@ export const configureWorkerModule = async ({
|
|
|
210
205
|
},
|
|
211
206
|
|
|
212
207
|
// Mutations
|
|
213
|
-
addWork: async ({ type, input, priority = 0, scheduled, originalWorkId, retries = 20 }
|
|
208
|
+
addWork: async ({ type, input, priority = 0, scheduled, originalWorkId, retries = 20 }) => {
|
|
214
209
|
if (!WorkerDirector.getAdapter(type)) {
|
|
215
210
|
throw new Error(`No plugin registered for type ${type}`);
|
|
216
211
|
}
|
|
217
212
|
|
|
218
213
|
const created = new Date();
|
|
219
|
-
const workId = await mutations.create(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
},
|
|
229
|
-
userId,
|
|
230
|
-
);
|
|
214
|
+
const workId = await mutations.create({
|
|
215
|
+
type,
|
|
216
|
+
input,
|
|
217
|
+
priority,
|
|
218
|
+
scheduled: scheduled || created,
|
|
219
|
+
originalWorkId,
|
|
220
|
+
retries,
|
|
221
|
+
created,
|
|
222
|
+
});
|
|
231
223
|
|
|
232
224
|
log(
|
|
233
225
|
`WorkerDirector -> Work added ${workId} (${type} / ${new Date(
|
|
234
226
|
scheduled || created,
|
|
235
227
|
).toISOString()} / ${retries})`,
|
|
236
|
-
{
|
|
237
|
-
userId,
|
|
238
|
-
},
|
|
239
228
|
);
|
|
240
229
|
|
|
241
230
|
const work = await WorkQueue.findOne(generateDbFilterById(workId), {});
|
|
242
231
|
|
|
243
|
-
WorkerDirector.events.emit(WorkerEventTypes.ADDED, { work
|
|
232
|
+
WorkerDirector.events.emit(WorkerEventTypes.ADDED, { work });
|
|
244
233
|
|
|
245
234
|
return work;
|
|
246
235
|
},
|
|
@@ -297,7 +286,7 @@ export const configureWorkerModule = async ({
|
|
|
297
286
|
});
|
|
298
287
|
try {
|
|
299
288
|
const workId = `${type}:${scheduled.getTime()}`;
|
|
300
|
-
const result = await
|
|
289
|
+
const result = await WorkQueue.findOneAndUpdate(
|
|
301
290
|
query,
|
|
302
291
|
{
|
|
303
292
|
$set: {
|
|
@@ -320,7 +309,7 @@ export const configureWorkerModule = async ({
|
|
|
320
309
|
returnDocument: 'after',
|
|
321
310
|
upsert: true,
|
|
322
311
|
},
|
|
323
|
-
)
|
|
312
|
+
);
|
|
324
313
|
|
|
325
314
|
if (!result.lastErrorObject.updatedExisting) {
|
|
326
315
|
log(
|
|
@@ -339,13 +328,13 @@ export const configureWorkerModule = async ({
|
|
|
339
328
|
}
|
|
340
329
|
},
|
|
341
330
|
|
|
342
|
-
doWork: (work,
|
|
343
|
-
return WorkerDirector.doWork(work,
|
|
331
|
+
doWork: (work, unchainedAPI) => {
|
|
332
|
+
return WorkerDirector.doWork(work, unchainedAPI);
|
|
344
333
|
},
|
|
345
334
|
|
|
346
335
|
finishWork,
|
|
347
336
|
|
|
348
|
-
deleteWork: async (workId
|
|
337
|
+
deleteWork: async (workId) => {
|
|
349
338
|
const workBeforeRemoval = await WorkQueue.findOne(
|
|
350
339
|
buildQuerySelector({
|
|
351
340
|
workId,
|
|
@@ -354,16 +343,16 @@ export const configureWorkerModule = async ({
|
|
|
354
343
|
);
|
|
355
344
|
if (!workBeforeRemoval) return null;
|
|
356
345
|
|
|
357
|
-
await mutations.delete(workId
|
|
346
|
+
await mutations.delete(workId);
|
|
358
347
|
|
|
359
348
|
const work = await WorkQueue.findOne(generateDbFilterById(workId), {});
|
|
360
349
|
|
|
361
|
-
WorkerDirector.events.emit(WorkerEventTypes.DELETED, { work
|
|
350
|
+
WorkerDirector.events.emit(WorkerEventTypes.DELETED, { work });
|
|
362
351
|
|
|
363
352
|
return work;
|
|
364
353
|
},
|
|
365
354
|
|
|
366
|
-
markOldWorkAsFailed: async ({ types, worker, referenceDate }
|
|
355
|
+
markOldWorkAsFailed: async ({ types, worker, referenceDate }) => {
|
|
367
356
|
const workQueue = await WorkQueue.find(
|
|
368
357
|
buildQuerySelector({
|
|
369
358
|
status: [WorkStatus.ALLOCATED],
|
|
@@ -371,26 +360,22 @@ export const configureWorkerModule = async ({
|
|
|
371
360
|
worker,
|
|
372
361
|
type: { $in: types },
|
|
373
362
|
}),
|
|
374
|
-
{
|
|
363
|
+
{ projection: { _id: true }, sort: { test: 1 } },
|
|
375
364
|
).toArray();
|
|
376
365
|
|
|
377
366
|
return Promise.all(
|
|
378
367
|
workQueue.map(({ _id }) =>
|
|
379
|
-
finishWork(
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
message:
|
|
388
|
-
'Director marked old work as failed after restart. This work was eventually running at the moment when node.js exited.',
|
|
389
|
-
},
|
|
390
|
-
worker,
|
|
368
|
+
finishWork(_id as string, {
|
|
369
|
+
finished: new Date(),
|
|
370
|
+
result: null,
|
|
371
|
+
success: false,
|
|
372
|
+
error: {
|
|
373
|
+
name: DIRECTOR_MARKED_FAILED_ERROR,
|
|
374
|
+
message:
|
|
375
|
+
'Director marked old work as failed after restart. This work was eventually running at the moment when node.js exited.',
|
|
391
376
|
},
|
|
392
|
-
|
|
393
|
-
),
|
|
377
|
+
worker,
|
|
378
|
+
}),
|
|
394
379
|
),
|
|
395
380
|
);
|
|
396
381
|
},
|
|
@@ -8,8 +8,8 @@ export const FailedRescheduler: IScheduler = {
|
|
|
8
8
|
label: 'Reschedule failed works',
|
|
9
9
|
version: '1.0.0',
|
|
10
10
|
|
|
11
|
-
actions: (
|
|
12
|
-
const handleFinishedWork = ({ work
|
|
11
|
+
actions: (unchainedAPI) => {
|
|
12
|
+
const handleFinishedWork = ({ work }: { work: Work }) => {
|
|
13
13
|
if (!work.success && work.retries > 0) {
|
|
14
14
|
const now = new Date();
|
|
15
15
|
const workDelayMs = work.scheduled.getTime() - work.created.getTime();
|
|
@@ -28,17 +28,14 @@ export const FailedRescheduler: IScheduler = {
|
|
|
28
28
|
}`,
|
|
29
29
|
);
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
userId,
|
|
41
|
-
);
|
|
31
|
+
unchainedAPI.modules.worker.addWork({
|
|
32
|
+
type: work.type,
|
|
33
|
+
input: work.input,
|
|
34
|
+
priority: work.priority,
|
|
35
|
+
originalWorkId: work.originalWorkId || work._id,
|
|
36
|
+
retries: work.retries - 1,
|
|
37
|
+
scheduled,
|
|
38
|
+
});
|
|
42
39
|
}
|
|
43
40
|
};
|
|
44
41
|
|
|
@@ -26,7 +26,7 @@ export const BaseWorker: IWorker<WorkerParams> = {
|
|
|
26
26
|
return floored;
|
|
27
27
|
},
|
|
28
28
|
|
|
29
|
-
actions: ({ workerId, worker }: WorkerParams,
|
|
29
|
+
actions: ({ workerId, worker }: WorkerParams, unchainedAPI) => {
|
|
30
30
|
const resolvedWorkerId = resolveWorkerId(workerId, worker.type);
|
|
31
31
|
log(`${worker.key} -> Initialized: ${resolvedWorkerId}`);
|
|
32
32
|
|
|
@@ -40,7 +40,7 @@ export const BaseWorker: IWorker<WorkerParams> = {
|
|
|
40
40
|
},
|
|
41
41
|
|
|
42
42
|
reset: async (referenceDate = new Date()) => {
|
|
43
|
-
await
|
|
43
|
+
await unchainedAPI.modules.worker.markOldWorkAsFailed({
|
|
44
44
|
types: WorkerDirector.getActivePluginTypes(false),
|
|
45
45
|
worker: workerId,
|
|
46
46
|
referenceDate,
|
|
@@ -55,7 +55,7 @@ export const BaseWorker: IWorker<WorkerParams> = {
|
|
|
55
55
|
fixedSchedule.schedules[0].s = [0]; // ignore seconds, always run on second 0
|
|
56
56
|
const nextDate = later.schedule(fixedSchedule).next(1, referenceDate);
|
|
57
57
|
nextDate.setMilliseconds(0);
|
|
58
|
-
return
|
|
58
|
+
return unchainedAPI.modules.worker.ensureOneWork({
|
|
59
59
|
type,
|
|
60
60
|
input: input(),
|
|
61
61
|
scheduled: nextDate,
|
|
@@ -76,7 +76,7 @@ export const BaseWorker: IWorker<WorkerParams> = {
|
|
|
76
76
|
const processRecursively = async (recursionCounter = 0) => {
|
|
77
77
|
if (maxWorkItemCount && maxWorkItemCount < recursionCounter) return null;
|
|
78
78
|
|
|
79
|
-
const work = await
|
|
79
|
+
const work = await unchainedAPI.modules.worker.allocateWork({
|
|
80
80
|
types: WorkerDirector.getActivePluginTypes(false),
|
|
81
81
|
worker: workerId,
|
|
82
82
|
});
|
|
@@ -84,18 +84,14 @@ export const BaseWorker: IWorker<WorkerParams> = {
|
|
|
84
84
|
let doneWork: Work | null = null;
|
|
85
85
|
|
|
86
86
|
if (work) {
|
|
87
|
-
const output = await
|
|
88
|
-
|
|
89
|
-
doneWork = await
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
worker: workerId,
|
|
96
|
-
},
|
|
97
|
-
'0',
|
|
98
|
-
);
|
|
87
|
+
const output = await unchainedAPI.modules.worker.doWork(work, unchainedAPI);
|
|
88
|
+
|
|
89
|
+
doneWork = await unchainedAPI.modules.worker.finishWork(work._id, {
|
|
90
|
+
...output,
|
|
91
|
+
finished: work.finished || new Date(),
|
|
92
|
+
started: work.started,
|
|
93
|
+
worker: workerId,
|
|
94
|
+
});
|
|
99
95
|
}
|
|
100
96
|
|
|
101
97
|
if (doneWork) return processRecursively(recursionCounter + 1);
|
|
@@ -11,13 +11,13 @@ export const EventListenerWorker: IWorker<{ workerId: string }> = {
|
|
|
11
11
|
version: '1.0.0',
|
|
12
12
|
type: 'EVENT_LISTENER',
|
|
13
13
|
|
|
14
|
-
actions: ({ workerId },
|
|
14
|
+
actions: ({ workerId }, unchainedAPI) => {
|
|
15
15
|
let onAdded: () => Promise<void>;
|
|
16
16
|
let onFinished: () => Promise<void>;
|
|
17
17
|
|
|
18
18
|
const baseWorkerActions = BaseWorker.actions(
|
|
19
19
|
{ workerId, worker: EventListenerWorker },
|
|
20
|
-
|
|
20
|
+
unchainedAPI,
|
|
21
21
|
);
|
|
22
22
|
return {
|
|
23
23
|
...baseWorkerActions,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Context } from '@unchainedshop/types/api';
|
|
2
1
|
import { IWorker, WorkerSchedule } from '@unchainedshop/types/worker';
|
|
3
2
|
import later from '@breejs/later';
|
|
4
3
|
import { BaseWorker } from './BaseWorker';
|
|
@@ -31,8 +30,8 @@ export const IntervalWorker: IWorker<WorkerParams> = {
|
|
|
31
30
|
version: '1.0.0',
|
|
32
31
|
type: 'CRON',
|
|
33
32
|
|
|
34
|
-
actions: ({ workerId, batchCount = 0, schedule = defaultSchedule },
|
|
35
|
-
const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker },
|
|
33
|
+
actions: ({ workerId, batchCount = 0, schedule = defaultSchedule }, unchainedAPI) => {
|
|
34
|
+
const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker }, unchainedAPI);
|
|
36
35
|
|
|
37
36
|
const intervalDelay = scheduleToInterval(schedule);
|
|
38
37
|
let intervalHandle: NodeJS.Timer;
|
|
@@ -1,32 +1,188 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
import { WorkStatus } from "../src/director/WorkStatus";
|
|
2
|
+
import { buildQuerySelector } from "../src/module/configureWorkerModule";
|
|
3
|
+
|
|
4
|
+
describe('Worker', () => {
|
|
5
|
+
|
|
6
|
+
describe("buildQuerySelector", () => {
|
|
7
|
+
it('Return correct filter object when passed no argument', async () => {
|
|
8
|
+
expect(buildQuerySelector({})).toEqual({ deleted: { '$exists': false } })
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('Return correct filter object when passed create, queryString, scheduled, status, types & workId', async () => {
|
|
12
|
+
const selector = buildQuerySelector({created: {start: new Date("2022-12-04T17:13:09.285Z"), end: new Date("2022-12-04T17:13:09.285Z") }, queryString: "hello world", scheduled: {end: new Date("2022-12-04T17:13:09.285Z"), start: new Date("2022-12-04T17:13:09.285Z")}, status: [WorkStatus.ALLOCATED], types: ['EMAIL'], workId: 'work-id'})
|
|
13
|
+
expect(selector).toEqual({
|
|
14
|
+
_id: 'work-id',
|
|
15
|
+
'$or': [
|
|
16
|
+
{
|
|
17
|
+
started: { '$exists': true },
|
|
18
|
+
finished: { '$exists': false },
|
|
19
|
+
deleted: { '$exists': false }
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
created: {
|
|
23
|
+
'$gte': new Date("2022-12-04T17:13:09.285Z"),
|
|
24
|
+
'$lte': new Date("2022-12-04T17:13:09.285Z")
|
|
25
|
+
},
|
|
26
|
+
scheduled: {
|
|
27
|
+
'$gte': new Date("2022-12-04T17:13:09.285Z"),
|
|
28
|
+
'$lte': new Date("2022-12-04T17:13:09.285Z")
|
|
29
|
+
},
|
|
30
|
+
type: { '$in': [ 'EMAIL' ] },
|
|
31
|
+
'$text': { '$search': 'hello world' }
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('Return correct filter object when passed queryString, scheduled, status, types & workId', async () => {
|
|
38
|
+
const selector = buildQuerySelector({ queryString: "hello world", scheduled: {end: new Date("2022-12-04T17:13:09.285Z"), start: new Date("2022-12-04T17:13:09.285Z")}, status: [WorkStatus.ALLOCATED], types: ['EMAIL'], workId: 'work-id'})
|
|
39
|
+
expect(selector).toEqual({
|
|
40
|
+
_id: 'work-id',
|
|
41
|
+
'$or': [
|
|
42
|
+
{
|
|
43
|
+
started: { '$exists': true },
|
|
44
|
+
finished: { '$exists': false },
|
|
45
|
+
deleted: { '$exists': false }
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
scheduled: {
|
|
49
|
+
'$gte': new Date("2022-12-04T17:13:09.285Z"),
|
|
50
|
+
'$lte': new Date("2022-12-04T17:13:09.285Z")
|
|
51
|
+
},
|
|
52
|
+
type: { '$in': [ 'EMAIL' ] },
|
|
53
|
+
'$text': { '$search': 'hello world' }
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('Return correct filter object when passed scheduled, status, types & workId', async () => {
|
|
60
|
+
const selector = buildQuerySelector({ scheduled: {end: new Date("2022-12-04T17:13:09.285Z"), start: new Date("2022-12-04T17:13:09.285Z")}, status: [WorkStatus.ALLOCATED], types: ['EMAIL'], workId: 'work-id'})
|
|
61
|
+
expect(selector).toEqual({
|
|
62
|
+
_id: 'work-id',
|
|
63
|
+
'$or': [
|
|
64
|
+
{
|
|
65
|
+
started: { '$exists': true },
|
|
66
|
+
finished: { '$exists': false },
|
|
67
|
+
deleted: { '$exists': false }
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
scheduled: {
|
|
71
|
+
'$gte': new Date("2022-12-04T17:13:09.285Z"),
|
|
72
|
+
'$lte': new Date("2022-12-04T17:13:09.285Z")
|
|
73
|
+
},
|
|
74
|
+
type: { '$in': [ 'EMAIL' ] },
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('Return correct filter object when passed status, types & workId', async () => {
|
|
81
|
+
const selector = buildQuerySelector({ status: [WorkStatus.ALLOCATED], types: ['EMAIL'], workId: 'work-id'})
|
|
82
|
+
expect(selector).toEqual({
|
|
83
|
+
_id: 'work-id',
|
|
84
|
+
'$or': [
|
|
85
|
+
{
|
|
86
|
+
started: { '$exists': true },
|
|
87
|
+
finished: { '$exists': false },
|
|
88
|
+
deleted: { '$exists': false }
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
type: { '$in': [ 'EMAIL' ] },
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('Return correct filter object when passed types & workId', async () => {
|
|
98
|
+
const selector = buildQuerySelector({ types: ['EMAIL'], workId: 'work-id'})
|
|
99
|
+
expect(selector).toEqual({
|
|
100
|
+
_id: 'work-id',
|
|
101
|
+
deleted: { '$exists': false },
|
|
102
|
+
type: { '$in': [ 'EMAIL' ] },
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('Return correct filter object when passed workId', async () => {
|
|
109
|
+
const selector = buildQuerySelector({ workId: 'work-id'})
|
|
110
|
+
expect(selector).toEqual({
|
|
111
|
+
_id: 'work-id',
|
|
112
|
+
deleted: { '$exists': false },
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('Create start should be set to start of unix timestamp if created.start not provided', async () => {
|
|
118
|
+
const selector = buildQuerySelector({ workId: 'work-id', created: {end: new Date("2022-12-04T17:13:09.285Z")}})
|
|
119
|
+
|
|
120
|
+
expect(selector).toEqual({
|
|
121
|
+
_id: 'work-id',
|
|
122
|
+
deleted: { '$exists': false },
|
|
123
|
+
created: {
|
|
124
|
+
'$gte': new Date(0),
|
|
125
|
+
'$lte': new Date("2022-12-04T17:13:09.285Z")
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
it('Create start should be set to start or unix timestamp if created.end not provided', async () => {
|
|
133
|
+
const selector = buildQuerySelector({ workId: 'work-id', created: {start: new Date("2022-12-04T17:13:09.285Z")}})
|
|
134
|
+
|
|
135
|
+
expect(selector).toEqual({
|
|
136
|
+
_id: 'work-id',
|
|
137
|
+
deleted: { '$exists': false },
|
|
138
|
+
created: { '$gte': new Date("2022-12-04T17:13:09.285Z")}
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
expect(buildQuerySelector({ workId: 'work-id', created: {}})).toEqual({
|
|
143
|
+
_id: 'work-id',
|
|
144
|
+
deleted: { '$exists': false },
|
|
145
|
+
created: { '$gte': new Date(0)}
|
|
146
|
+
}
|
|
147
|
+
)
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
it('scheduled start should be set to start of unix timestamp if scheduled.start not provided', async () => {
|
|
152
|
+
const selector = buildQuerySelector({ workId: 'work-id', scheduled: {end: new Date("2022-12-04T17:13:09.285Z")}})
|
|
153
|
+
|
|
154
|
+
expect(selector).toEqual({
|
|
155
|
+
_id: 'work-id',
|
|
156
|
+
deleted: { '$exists': false },
|
|
157
|
+
scheduled: {
|
|
158
|
+
'$gte': new Date(0),
|
|
159
|
+
'$lte': new Date("2022-12-04T17:13:09.285Z")
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
it('Scheduled start should be set to start or unix timestamp if scheduled.end not provided', async () => {
|
|
167
|
+
const selector = buildQuerySelector({ workId: 'work-id', scheduled: {start: new Date("2022-12-04T17:13:09.285Z")}})
|
|
168
|
+
|
|
169
|
+
expect(selector).toEqual({
|
|
170
|
+
_id: 'work-id',
|
|
171
|
+
deleted: { '$exists': false },
|
|
172
|
+
scheduled: { '$gte': new Date("2022-12-04T17:13:09.285Z")}
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
expect(buildQuerySelector({ workId: 'work-id', scheduled: {}})).toEqual({
|
|
177
|
+
_id: 'work-id',
|
|
178
|
+
deleted: { '$exists': false },
|
|
179
|
+
scheduled: { '$gte': new Date(0)}
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
})
|
|
187
|
+
|
|
32
188
|
});
|