@unchainedshop/core-worker 3.1.1 → 3.1.5

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.
Files changed (41) hide show
  1. package/lib/db/WorkQueueCollection.d.ts.map +1 -1
  2. package/lib/module/configureWorkerModule.d.ts.map +1 -1
  3. package/package.json +4 -5
  4. package/src/module/buildQuerySelector.test.ts +19 -17
  5. package/jest.config.js +0 -17
  6. package/lib/db/WorkQueueSchema.d.ts +0 -3
  7. package/lib/db/WorkQueueSchema.d.ts.map +0 -1
  8. package/lib/db/WorkQueueSchema.js +0 -20
  9. package/lib/db/WorkQueueSchema.js.map +0 -1
  10. package/lib/director/WorkStatus.d.ts +0 -8
  11. package/lib/director/WorkStatus.d.ts.map +0 -1
  12. package/lib/director/WorkStatus.js +0 -9
  13. package/lib/director/WorkStatus.js.map +0 -1
  14. package/lib/director/WorkerAdapter.d.ts +0 -3
  15. package/lib/director/WorkerAdapter.d.ts.map +0 -1
  16. package/lib/director/WorkerAdapter.js +0 -11
  17. package/lib/director/WorkerAdapter.js.map +0 -1
  18. package/lib/director/WorkerDirector.d.ts +0 -4
  19. package/lib/director/WorkerDirector.d.ts.map +0 -1
  20. package/lib/director/WorkerDirector.js +0 -72
  21. package/lib/director/WorkerDirector.js.map +0 -1
  22. package/lib/director/WorkerEventTypes.d.ts +0 -8
  23. package/lib/director/WorkerEventTypes.d.ts.map +0 -1
  24. package/lib/director/WorkerEventTypes.js +0 -12
  25. package/lib/director/WorkerEventTypes.js.map +0 -1
  26. package/lib/schedulers/FailedRescheduler.d.ts +0 -6
  27. package/lib/schedulers/FailedRescheduler.d.ts.map +0 -1
  28. package/lib/schedulers/FailedRescheduler.js +0 -45
  29. package/lib/schedulers/FailedRescheduler.js.map +0 -1
  30. package/lib/workers/BaseWorker.d.ts +0 -8
  31. package/lib/workers/BaseWorker.d.ts.map +0 -1
  32. package/lib/workers/BaseWorker.js +0 -81
  33. package/lib/workers/BaseWorker.js.map +0 -1
  34. package/lib/workers/EventListenerWorker.d.ts +0 -6
  35. package/lib/workers/EventListenerWorker.d.ts.map +0 -1
  36. package/lib/workers/EventListenerWorker.js +0 -46
  37. package/lib/workers/EventListenerWorker.js.map +0 -1
  38. package/lib/workers/IntervalWorker.d.ts +0 -9
  39. package/lib/workers/IntervalWorker.d.ts.map +0 -1
  40. package/lib/workers/IntervalWorker.js +0 -38
  41. package/lib/workers/IntervalWorker.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"WorkQueueCollection.d.ts","sourceRoot":"","sources":["../../src/db/WorkQueueCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAkB,MAAM,wBAAwB,CAAC;AAIjE,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,OAAO,YAAY;CACpB;AAED,MAAM,MAAM,IAAI,GAAG;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,eAAe,CAAC;AAEpB,eAAO,MAAM,mBAAmB,OAAc,OAAO,CAAC,EAAE,sCA8BvD,CAAC"}
1
+ {"version":3,"file":"WorkQueueCollection.d.ts","sourceRoot":"","sources":["../../src/db/WorkQueueCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAkB,MAAM,wBAAwB,CAAC;AAIjE,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,OAAO,YAAY;CACpB;AAED,MAAM,MAAM,IAAI,GAAG;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,eAAe,CAAC;AAEpB,eAAO,MAAM,mBAAmB,GAAU,IAAI,OAAO,CAAC,EAAE,sCA8BvD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"configureWorkerModule.d.ts","sourceRoot":"","sources":["../../src/module/configureWorkerModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,OAAO,EAEP,WAAW,EACZ,MAAM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EAAE,CAAC;EA+E9B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-worker",
3
- "version": "3.1.1",
3
+ "version": "3.1.5",
4
4
  "main": "lib/worker-index.js",
5
5
  "types": "lib/worker-index.d.ts",
6
6
  "type": "module",
@@ -9,8 +9,8 @@
9
9
  "build": "tsc -b",
10
10
  "prepublishOnly": "npm run clean && npm run build",
11
11
  "watch": "tsc -w",
12
- "test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
13
- "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
12
+ "test": "tsx --test",
13
+ "test:watch": "tsx --test --watch"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
@@ -37,8 +37,7 @@
37
37
  "devDependencies": {
38
38
  "@types/breejs__later": "^4.1.5",
39
39
  "@types/node": "^22.13.4",
40
- "jest": "^29.7.0",
41
- "ts-jest": "^29.2.5",
40
+ "tsx": "^4.19.2",
42
41
  "typescript": "^5.7.3"
43
42
  }
44
43
  }
@@ -1,13 +1,15 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert';
1
3
  import { WorkStatus } from '../worker-index.js';
2
4
  import { buildQuerySelector } from './configureWorkerModule.js';
3
5
 
4
6
  describe('Worker', () => {
5
7
  describe('buildQuerySelector', () => {
6
8
  it('Return correct filter object when passed no argument', () => {
7
- expect(buildQuerySelector({})).toEqual({ deleted: { $exists: false } });
9
+ assert.deepStrictEqual(buildQuerySelector({}), { deleted: { $exists: false } });
8
10
  });
9
11
 
10
- it('Return correct filter object when passed create, queryString, scheduled, status, types & workId', () => {
12
+ it('Return correct filter object when passed create, queryString, scheduled, status, types & workId', () => {
11
13
  const selector = buildQuerySelector({
12
14
  created: {
13
15
  start: new Date('2022-12-04T17:13:09.285Z'),
@@ -22,7 +24,7 @@ describe('Worker', () => {
22
24
  types: ['EMAIL'],
23
25
  workId: 'work-id',
24
26
  });
25
- expect(selector).toEqual({
27
+ assert.deepStrictEqual(selector, {
26
28
  _id: 'work-id',
27
29
  $or: [
28
30
  {
@@ -55,7 +57,7 @@ describe('Worker', () => {
55
57
  types: ['EMAIL'],
56
58
  workId: 'work-id',
57
59
  });
58
- expect(selector).toEqual({
60
+ assert.deepStrictEqual(selector, {
59
61
  _id: 'work-id',
60
62
  $or: [
61
63
  {
@@ -83,7 +85,7 @@ describe('Worker', () => {
83
85
  types: ['EMAIL'],
84
86
  workId: 'work-id',
85
87
  });
86
- expect(selector).toEqual({
88
+ assert.deepStrictEqual(selector, {
87
89
  _id: 'work-id',
88
90
  $or: [
89
91
  {
@@ -106,7 +108,7 @@ describe('Worker', () => {
106
108
  types: ['EMAIL'],
107
109
  workId: 'work-id',
108
110
  });
109
- expect(selector).toEqual({
111
+ assert.deepStrictEqual(selector, {
110
112
  _id: 'work-id',
111
113
  $or: [
112
114
  {
@@ -121,7 +123,7 @@ describe('Worker', () => {
121
123
 
122
124
  it('Return correct filter object when passed types & workId', () => {
123
125
  const selector = buildQuerySelector({ types: ['EMAIL'], workId: 'work-id' });
124
- expect(selector).toEqual({
126
+ assert.deepStrictEqual(selector, {
125
127
  _id: 'work-id',
126
128
  deleted: { $exists: false },
127
129
  type: { $in: ['EMAIL'] },
@@ -130,19 +132,19 @@ describe('Worker', () => {
130
132
 
131
133
  it('Return correct filter object when passed workId', () => {
132
134
  const selector = buildQuerySelector({ workId: 'work-id' });
133
- expect(selector).toEqual({
135
+ assert.deepStrictEqual(selector, {
134
136
  _id: 'work-id',
135
137
  deleted: { $exists: false },
136
138
  });
137
139
  });
138
140
 
139
- it('Create start should be set to start of unix timestamp if created.start not provided', () => {
141
+ it('Create start should be set to start of unix timestamp if created.start not provided', () => {
140
142
  const selector = buildQuerySelector({
141
143
  workId: 'work-id',
142
144
  created: { end: new Date('2022-12-04T17:13:09.285Z') },
143
145
  });
144
146
 
145
- expect(selector).toEqual({
147
+ assert.deepStrictEqual(selector, {
146
148
  _id: 'work-id',
147
149
  deleted: { $exists: false },
148
150
  created: {
@@ -152,32 +154,32 @@ describe('Worker', () => {
152
154
  });
153
155
  });
154
156
 
155
- it('Create start should be set to start or unix timestamp if created.end not provided', () => {
157
+ it('Create start should be set to start or unix timestamp if created.end not provided', () => {
156
158
  const selector = buildQuerySelector({
157
159
  workId: 'work-id',
158
160
  created: { start: new Date('2022-12-04T17:13:09.285Z') },
159
161
  });
160
162
 
161
- expect(selector).toEqual({
163
+ assert.deepStrictEqual(selector, {
162
164
  _id: 'work-id',
163
165
  deleted: { $exists: false },
164
166
  created: { $gte: new Date('2022-12-04T17:13:09.285Z') },
165
167
  });
166
168
 
167
- expect(buildQuerySelector({ workId: 'work-id', created: {} })).toEqual({
169
+ assert.deepStrictEqual(buildQuerySelector({ workId: 'work-id', created: {} }), {
168
170
  _id: 'work-id',
169
171
  deleted: { $exists: false },
170
172
  created: { $gte: new Date(0) },
171
173
  });
172
174
  });
173
175
 
174
- it('scheduled start should be set to start of unix timestamp if scheduled.start not provided', () => {
176
+ it('scheduled start should be set to start of unix timestamp if scheduled.start not provided', () => {
175
177
  const selector = buildQuerySelector({
176
178
  workId: 'work-id',
177
179
  scheduled: { end: new Date('2022-12-04T17:13:09.285Z') },
178
180
  });
179
181
 
180
- expect(selector).toEqual({
182
+ assert.deepStrictEqual(selector, {
181
183
  _id: 'work-id',
182
184
  deleted: { $exists: false },
183
185
  scheduled: {
@@ -193,13 +195,13 @@ describe('Worker', () => {
193
195
  scheduled: { start: new Date('2022-12-04T17:13:09.285Z') },
194
196
  });
195
197
 
196
- expect(selector).toEqual({
198
+ assert.deepStrictEqual(selector, {
197
199
  _id: 'work-id',
198
200
  deleted: { $exists: false },
199
201
  scheduled: { $gte: new Date('2022-12-04T17:13:09.285Z') },
200
202
  });
201
203
 
202
- expect(buildQuerySelector({ workId: 'work-id', scheduled: {} })).toEqual({
204
+ assert.deepStrictEqual(buildQuerySelector({ workId: 'work-id', scheduled: {} }), {
203
205
  _id: 'work-id',
204
206
  deleted: { $exists: false },
205
207
  scheduled: { $gte: new Date(0) },
package/jest.config.js DELETED
@@ -1,17 +0,0 @@
1
- /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
- export default {
3
- preset: 'ts-jest/presets/default-esm', // or other ESM presets
4
- testEnvironment: 'node',
5
- extensionsToTreatAsEsm: ['.ts'],
6
- transform: {
7
- '^.+\\.tsx?$': [
8
- 'ts-jest',
9
- {
10
- useESM: true,
11
- },
12
- ],
13
- },
14
- moduleNameMapper: {
15
- '^(\\.{1,2}/.*)\\.js$': '$1',
16
- },
17
- };
@@ -1,3 +0,0 @@
1
- import SimpleSchema from 'simpl-schema';
2
- export declare const WorkQueueSchema: SimpleSchema;
3
- //# sourceMappingURL=WorkQueueSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkQueueSchema.d.ts","sourceRoot":"","sources":["../../src/db/WorkQueueSchema.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,eAAO,MAAM,eAAe,cAmB3B,CAAC"}
@@ -1,20 +0,0 @@
1
- import { Schemas } from '@unchainedshop/utils';
2
- import SimpleSchema from 'simpl-schema';
3
- export const WorkQueueSchema = new SimpleSchema({
4
- finished: Date,
5
- originalWorkId: { type: String },
6
- priority: { type: Number, required: true },
7
- retries: { type: Number, required: true },
8
- scheduled: { type: Date, required: true },
9
- started: Date,
10
- success: Boolean,
11
- timeout: Number,
12
- type: { type: String, required: true },
13
- worker: String,
14
- // Worker data
15
- input: { type: Object, blackbox: true },
16
- result: { type: Object, blackbox: true },
17
- error: { type: Object, blackbox: true },
18
- ...Schemas.timestampFields,
19
- }, { requiredByDefault: false });
20
- //# sourceMappingURL=WorkQueueSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkQueueSchema.js","sourceRoot":"","sources":["../../src/db/WorkQueueSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,YAAY,CAC7C;IACE,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;IAChC,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC1C,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACzC,SAAS,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;IACzC,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,OAAO;IAChB,OAAO,EAAE,MAAM;IACf,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACtC,MAAM,EAAE,MAAM;IACd,cAAc;IACd,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACvC,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACxC,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACvC,GAAG,OAAO,CAAC,eAAe;CAC3B,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
@@ -1,8 +0,0 @@
1
- export declare enum WorkStatus {
2
- NEW = "NEW",
3
- ALLOCATED = "ALLOCATED",
4
- SUCCESS = "SUCCESS",
5
- FAILED = "FAILED",
6
- DELETED = "DELETED"
7
- }
8
- //# sourceMappingURL=WorkStatus.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkStatus.d.ts","sourceRoot":"","sources":["../../src/director/WorkStatus.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,OAAO,YAAY;CACpB"}
@@ -1,9 +0,0 @@
1
- export var WorkStatus;
2
- (function (WorkStatus) {
3
- WorkStatus["NEW"] = "NEW";
4
- WorkStatus["ALLOCATED"] = "ALLOCATED";
5
- WorkStatus["SUCCESS"] = "SUCCESS";
6
- WorkStatus["FAILED"] = "FAILED";
7
- WorkStatus["DELETED"] = "DELETED";
8
- })(WorkStatus || (WorkStatus = {}));
9
- //# sourceMappingURL=WorkStatus.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkStatus.js","sourceRoot":"","sources":["../../src/director/WorkStatus.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,yBAAW,CAAA;IACX,qCAAuB,CAAA;IACvB,iCAAmB,CAAA;IACnB,+BAAiB,CAAA;IACjB,iCAAmB,CAAA;AACrB,CAAC,EANW,UAAU,KAAV,UAAU,QAMrB"}
@@ -1,3 +0,0 @@
1
- import { IWorkerAdapter } from '@unchainedshop/types/worker.js';
2
- export declare const WorkerAdapter: Omit<IWorkerAdapter<any, void>, 'key' | 'label' | 'type' | 'version'>;
3
- //# sourceMappingURL=WorkerAdapter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkerAdapter.d.ts","sourceRoot":"","sources":["../../src/director/WorkerAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,eAAO,MAAM,aAAa,EAAE,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAU/F,CAAC"}
@@ -1,11 +0,0 @@
1
- import { log, LogLevel } from '@unchainedshop/logger';
2
- export const WorkerAdapter = {
3
- external: false,
4
- async doWork() {
5
- return { success: false, result: null };
6
- },
7
- log(message, { level = LogLevel.Debug, ...options } = {}) {
8
- return log(message, { level, ...options });
9
- },
10
- };
11
- //# sourceMappingURL=WorkerAdapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WorkerAdapter.js","sourceRoot":"","sources":["../../src/director/WorkerAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,CAAC,MAAM,aAAa,GAA0E;IAClG,QAAQ,EAAE,KAAK;IAEf,KAAK,CAAC,MAAM;QACV,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC1C,CAAC;IAED,GAAG,CAAC,OAAe,EAAE,EAAE,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE;QAC9D,OAAO,GAAG,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC7C,CAAC;CACF,CAAC"}
@@ -1,4 +0,0 @@
1
- import { IWorkerDirector } from '@unchainedshop/types/worker.js';
2
- export declare const DIRECTOR_MARKED_FAILED_ERROR = "DIRECTOR_MARKED_FAILED";
3
- export declare const WorkerDirector: IWorkerDirector;
4
- //# sourceMappingURL=WorkerDirector.d.ts.map
@@ -1 +0,0 @@
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,72 +0,0 @@
1
- import { log, LogLevel } from '@unchainedshop/logger';
2
- import { BaseDirector } from '@unchainedshop/utils';
3
- export const DIRECTOR_MARKED_FAILED_ERROR = 'DIRECTOR_MARKED_FAILED';
4
- const AutoScheduleMap = new Map();
5
- const baseDirector = BaseDirector('WorkerDirector', {
6
- adapterKeyField: 'key',
7
- });
8
- export const WorkerDirector = {
9
- ...baseDirector,
10
- getActivePluginTypes: ({ external } = {}) => {
11
- return WorkerDirector.getAdapters()
12
- .filter((adapter) => {
13
- if (external === null || external === undefined)
14
- return true;
15
- return Boolean(adapter.external) === external;
16
- })
17
- .map((adapter) => adapter.type);
18
- },
19
- registerAdapter: (Adapter) => {
20
- if (WorkerDirector.getAdapterByType(Adapter.type))
21
- throw new Error(`WorkerDirector: There is already a adapter registered with type: ${Adapter.type}`);
22
- baseDirector.registerAdapter(Adapter);
23
- },
24
- disableAutoscheduling: (type) => {
25
- const config = AutoScheduleMap.get(type);
26
- AutoScheduleMap.set(type, { ...config, schedule: null });
27
- },
28
- unregisterAdapter: (key) => {
29
- const adapter = WorkerDirector.getAdapter(key);
30
- const result = baseDirector.unregisterAdapter(key);
31
- if (adapter) {
32
- AutoScheduleMap.forEach((workItemConfiguration, scheduleId) => {
33
- if (workItemConfiguration.type === adapter.type) {
34
- AutoScheduleMap.delete(scheduleId);
35
- }
36
- });
37
- }
38
- return result;
39
- },
40
- configureAutoscheduling: (workItemConfiguration) => {
41
- const adapter = WorkerDirector.getAdapterByType(workItemConfiguration.type);
42
- AutoScheduleMap.set(workItemConfiguration.scheduleId || workItemConfiguration.type, workItemConfiguration);
43
- log(`WorkerDirector -> Configured ${adapter.type} ${adapter.key}@${adapter.version} (${adapter.label}) for Autorun at ${workItemConfiguration.schedule}`);
44
- },
45
- getAutoSchedules: () => Array.from(AutoScheduleMap),
46
- getAdapterByType: (type) => {
47
- const adapters = WorkerDirector.getAdapters({
48
- adapterFilter: (Adapter) => {
49
- return type === Adapter.type;
50
- },
51
- });
52
- return adapters?.[0];
53
- },
54
- doWork: async ({ type, input, _id: workId }, unchainedAPI) => {
55
- const adapter = WorkerDirector.getAdapterByType(type);
56
- if (!adapter) {
57
- log(`WorkerDirector: No registered adapter for type: ${type}`);
58
- }
59
- try {
60
- const output = await adapter.doWork(input, unchainedAPI, workId);
61
- return output;
62
- }
63
- catch (error) {
64
- // DO not use this as flow control. The adapter should catch expected errors and return status: FAILED
65
- log('DO not use this as flow control.', { level: LogLevel.Verbose });
66
- log(`WorkerDirector -> Error doing work ${type}: ${error.message}`);
67
- const errorOutput = { error, success: false };
68
- return errorOutput;
69
- }
70
- },
71
- };
72
- //# sourceMappingURL=WorkerDirector.js.map
@@ -1 +0,0 @@
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,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;QAC3B,IAAI,cAAc,CAAC,gBAAgB,CAAC,O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OCATED = "WORK_ALLOCATED",
4
- FINISHED = "WORK_FINISHED",
5
- DELETED = "WORK_DELETED",
6
- RESCHEDULED = "WORK_RESCHEDULED"
7
- }
8
- //# sourceMappingURL=WorkerEventTypes.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,12 +0,0 @@
1
- export var WorkerEventTypes;
2
- (function (WorkerEventTypes) {
3
- WorkerEventTypes["ADDED"] = "WORK_ADDED";
4
- WorkerEventTypes["ALLOCATED"] = "WORK_ALLOCATED";
5
- WorkerEventTypes["FINISHED"] = "WORK_FINISHED";
6
- WorkerEventTypes["DELETED"] = "WORK_DELETED";
7
- WorkerEventTypes["RESCHEDULED"] = "WORK_RESCHEDULED";
8
- })(WorkerEventTypes || (WorkerEventTypes = {}));
9
- // The difference between `done` and `finished` is, that work is `done` after
10
- // it was computed (no DB write, could be external) and `finished` after
11
- // the changes are written to the DB
12
- //# sourceMappingURL=WorkerEventTypes.js.map
@@ -1 +0,0 @@
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;AAED,6EAA6E;AAC7E,wEAAwE;AACxE,oCAAoC"}
@@ -1,6 +0,0 @@
1
- import { IScheduler, WorkData } from '@unchainedshop/types/worker.js';
2
- export interface FailedReschedulerParams {
3
- retryInput?: (workData: WorkData, priorInput: Record<string, any>) => Promise<Record<string, any> | null>;
4
- }
5
- export declare const FailedRescheduler: IScheduler<FailedReschedulerParams>;
6
- //# sourceMappingURL=FailedRescheduler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FailedRescheduler.d.ts","sourceRoot":"","sources":["../../src/schedulers/FailedRescheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAK5E,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,CACX,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC5B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;CAC1C;AAED,eAAO,MAAM,iBAAiB,EAAE,UAAU,CAAC,uBAAuB,CAsDjE,CAAC"}
@@ -1,45 +0,0 @@
1
- import { log } from '@unchainedshop/logger';
2
- import { subscribe } from '@unchainedshop/events';
3
- import { WorkerEventTypes } from '../director/WorkerEventTypes.js';
4
- export const FailedRescheduler = {
5
- key: 'shop.unchained.scheduler.failed',
6
- label: 'Reschedule failed works',
7
- version: '1.0.0',
8
- actions: ({ retryInput }, unchainedAPI) => {
9
- const handleFinishedWork = async ({ payload: work }) => {
10
- if (!work.success && work.retries > 0) {
11
- const now = new Date();
12
- const workDelayMs = work.scheduled.getTime() - work.created.getTime();
13
- // In short: Double the delay of the old work or delay for 5 seconds
14
- const scheduled = workDelayMs > 1000
15
- ? new Date(now.getTime() + workDelayMs * 2)
16
- : new Date(now.setSeconds(now.getSeconds() + 5));
17
- log(`${FailedRescheduler.key} -> Reschedule failed work ${work._id} ${work.type} for ${scheduled.toISOString()} (in ${Math.round(workDelayMs / 1000)}). Remaining retries: ${work.retries}`);
18
- const workData = {
19
- type: work.type,
20
- priority: work.priority,
21
- originalWorkId: work.originalWorkId || work._id,
22
- retries: work.retries - 1,
23
- timeout: work.timeout,
24
- scheduled,
25
- };
26
- if (retryInput) {
27
- workData.input = await retryInput(workData, work.input);
28
- }
29
- else {
30
- workData.input = work.input;
31
- }
32
- unchainedAPI.modules.worker.addWork(workData);
33
- }
34
- };
35
- return {
36
- start() {
37
- subscribe(WorkerEventTypes.FINISHED, handleFinishedWork);
38
- },
39
- stop() {
40
- /* */
41
- },
42
- };
43
- },
44
- };
45
- //# sourceMappingURL=FailedRescheduler.js.map
@@ -1 +0,0 @@
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,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AASnE,MAAM,CAAC,MAAM,iBAAiB,GAAwC;IACpE,GAAG,EAAE,iCAAiC;IACtC,KAAK,EAAE,yBAAyB;IAChC,OAAO,EAAE,OAAO;IAEhB,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,YAAY,EAAE,EAAE;QACxC,MAAM,kBAAkB,GAAG,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAqB,EAAE,EAAE;YACxE,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;gBACtC,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,MAAM,QAAQ,GAAa;oBACzB,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,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,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,SAAS;iBACV,CAAC;gBAEF,IAAI,UAAU,EAAE,CAAC;oBACf,QAAQ,CAAC,KAAK,GAAG,MAAM,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC1D,CAAC;qBAAM,CAAC;oBACN,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;gBAC9B,CAAC;gBAED,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAChD,CAAC;QACH,CAAC,CAAC;QAEF,OAAO;YACL,KAAK;gBACH,SAAS,CAAO,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;YACjE,CAAC;YAED,IAAI;gBACF,KAAK;YACP,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -1,8 +0,0 @@
1
- import { IWorker } from '@unchainedshop/types/worker.js';
2
- interface WorkerParams {
3
- workerId?: string;
4
- worker: IWorker<any>;
5
- }
6
- export declare const BaseWorker: IWorker<WorkerParams>;
7
- export {};
8
- //# sourceMappingURL=BaseWorker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BaseWorker.d.ts","sourceRoot":"","sources":["../../src/workers/BaseWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAY,MAAM,gCAAgC,CAAC;AAKnE,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,CAuF5C,CAAC"}
@@ -1,81 +0,0 @@
1
- import later from '@breejs/later';
2
- import { log } from '@unchainedshop/logger';
3
- import { WorkerDirector } from '../director/WorkerDirector.js';
4
- export const BaseWorker = {
5
- key: 'shop.unchained.worker.base',
6
- label: 'Base worker. Do not use this directly.',
7
- version: '1.0.0',
8
- type: 'BASE',
9
- external: false,
10
- getFloorDate: (date = new Date()) => {
11
- const floored = new Date(Math.floor(date.getTime() / 1000) * 1000);
12
- return floored;
13
- },
14
- actions: ({ workerId, worker }, unchainedAPI) => {
15
- log(`${worker.key} -> Initialized ${worker.type}`);
16
- const workerActions = {
17
- start() {
18
- throw new Error(`Not implemented on ${this.constructor.key}`);
19
- },
20
- stop() {
21
- throw new Error(`Not implemented on ${this.constructor.key}`);
22
- },
23
- reset: async (referenceDate = new Date()) => {
24
- await unchainedAPI.modules.worker.markOldWorkAsFailed({
25
- types: WorkerDirector.getActivePluginTypes({ external: false }),
26
- worker: workerId,
27
- referenceDate,
28
- });
29
- },
30
- autorescheduleTypes: async ({ referenceDate }) => {
31
- return Promise.all(WorkerDirector.getAutoSchedules().map(async ([scheduleId, workConfig]) => {
32
- if (!workConfig.schedule) {
33
- await unchainedAPI.modules.worker.ensureNoWork({
34
- type: workConfig.type,
35
- priority: workConfig.priority || 0,
36
- scheduleId,
37
- });
38
- return null;
39
- }
40
- const fixedSchedule = { ...workConfig.schedule };
41
- fixedSchedule.schedules[0].s = [0]; // ignore seconds, always run on second 0
42
- const nextDate = later.schedule(fixedSchedule).next(1, referenceDate);
43
- nextDate.setMilliseconds(0);
44
- const workData = {
45
- type: workConfig.type,
46
- scheduleId,
47
- scheduled: nextDate,
48
- timeout: workConfig.timeout,
49
- priority: workConfig.priority || 0,
50
- retries: workConfig.retries || 0,
51
- };
52
- if (workConfig.input) {
53
- workData.input = await workConfig.input(workData);
54
- // A work input fn can skip auto scheduling a new record
55
- // when it explicitly returns a falsish input instead of a dictionary
56
- if (!workData.input)
57
- return null;
58
- }
59
- return unchainedAPI.modules.worker.ensureOneWork(workData);
60
- }));
61
- },
62
- process: async ({ maxWorkItemCount, referenceDate }) => {
63
- await workerActions.autorescheduleTypes({
64
- referenceDate,
65
- });
66
- const processRecursively = async (recursionCounter = 0) => {
67
- if (maxWorkItemCount && maxWorkItemCount < recursionCounter)
68
- return null;
69
- const doneWork = await unchainedAPI.modules.worker.processNextWork(unchainedAPI, workerId);
70
- if (doneWork)
71
- return processRecursively(recursionCounter + 1);
72
- return null;
73
- };
74
- await processRecursively();
75
- },
76
- };
77
- workerActions.reset();
78
- return workerActions;
79
- },
80
- };
81
- //# sourceMappingURL=BaseWorker.js.map
@@ -1 +0,0 @@
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,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAO/D,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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AC,EAAE,EAAE;oBACxD,IAAI,gBAAgB,IAAI,gBAAgB,GAAG,gBAAgB;wBAAE,OAAO,IAAI,CAAC;oBACzE,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;oBAC3F,IAAI,QAAQ;wBAAE,OAAO,kBAAkB,CAAC,gBAAgB,GAAG,CAAC,CAAC,CAAC;oBAC9D,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"}
@@ -1,6 +0,0 @@
1
- import { IWorker } from '@unchainedshop/types/worker.js';
2
- export interface EventListenerWorkerParams {
3
- workerId?: string;
4
- }
5
- export declare const EventListenerWorker: IWorker<EventListenerWorkerParams>;
6
- //# sourceMappingURL=EventListenerWorker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EventListenerWorker.d.ts","sourceRoot":"","sources":["../../src/workers/EventListenerWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAgBzD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,mBAAmB,EAAE,OAAO,CAAC,yBAAyB,CAyClE,CAAC"}
@@ -1,46 +0,0 @@
1
- import { subscribe } from '@unchainedshop/events';
2
- import { WorkerEventTypes } from '../director/WorkerEventTypes.js';
3
- import { BaseWorker } from './BaseWorker.js';
4
- function debounce(func, wait) {
5
- let timeout;
6
- return (...args) => {
7
- clearTimeout(timeout);
8
- timeout = setTimeout(() => {
9
- timeout = null;
10
- func(...args);
11
- }, wait);
12
- };
13
- }
14
- export const EventListenerWorker = {
15
- ...BaseWorker,
16
- key: 'shop.unchained.worker.event-listener',
17
- label: 'Allocates work on events. This worker does not make sense on multiple containers.',
18
- version: '1.0.0',
19
- type: 'EVENT_LISTENER',
20
- actions: ({ workerId }, unchainedAPI) => {
21
- const baseWorkerActions = BaseWorker.actions({ workerId, worker: EventListenerWorker }, unchainedAPI);
22
- // Debounce in the event of many work queue events conflicting with each other
23
- const processWorkQueue = debounce(async () => {
24
- await baseWorkerActions.process({
25
- maxWorkItemCount: 1, // only one work item at a time, else we could end up in a loop
26
- referenceDate: EventListenerWorker.getFloorDate(),
27
- });
28
- }, 300);
29
- return {
30
- ...baseWorkerActions,
31
- start() {
32
- subscribe(WorkerEventTypes.ADDED, processWorkQueue);
33
- subscribe(WorkerEventTypes.FINISHED, processWorkQueue);
34
- setTimeout(async () => {
35
- await baseWorkerActions.autorescheduleTypes({
36
- referenceDate: EventListenerWorker.getFloorDate(),
37
- });
38
- }, 300);
39
- },
40
- stop() {
41
- /* */
42
- },
43
- };
44
- },
45
- };
46
- //# sourceMappingURL=EventListenerWorker.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EventListenerWorker.js","sourceRoot":"","sources":["../../src/workers/EventListenerWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,SAAS,QAAQ,CAAkC,IAAO,EAAE,IAAI;IAC9D,IAAI,OAAO,CAAC;IACZ,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE;QACjB,YAAY,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,OAAO,GAAG,IAAI,CAAC;YACf,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAChB,CAAC,EAAE,IAAI,CAAC,CAAC;IACX,CAAC,CAAC;AACJ,CAAC;AAMD,MAAM,CAAC,MAAM,mBAAmB,GAAuC;IACrE,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,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,CAC1C,EAAE,QAAQ,EAAE,MAAM,EAAE,mBAAmB,EAAE,EACzC,YAAY,CACb,CAAC;QAEF,8EAA8E;QAC9E,MAAM,gBAAgB,GAAG,QAAQ,CAAsB,KAAK,IAAI,EAAE;YAChE,MAAM,iBAAiB,CAAC,OAAO,CAAC;gBAC9B,gBAAgB,EAAE,CAAC,EAAE,+DAA+D;gBACpF,aAAa,EAAE,mBAAmB,CAAC,YAAY,EAAE;aAClD,CAAC,CAAC;QACL,CAAC,EAAE,GAAG,CAAC,CAAC;QAER,OAAO;YACL,GAAG,iBAAiB;YAEpB,KAAK;gBACH,SAAS,CAAC,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;gBACpD,SAAS,CAAC,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;gBAEvD,UAAU,CAAC,KAAK,IAAI,EAAE;oBACpB,MAAM,iBAAiB,CAAC,mBAAmB,CAAC;wBAC1C,aAAa,EAAE,mBAAmB,CAAC,YAAY,EAAE;qBAClD,CAAC,CAAC;gBACL,CAAC,EAAE,GAAG,CAAC,CAAC;YACV,CAAC;YAED,IAAI;gBACF,KAAK;YACP,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -1,9 +0,0 @@
1
- import { IWorker, WorkerSchedule } from '@unchainedshop/types/worker.js';
2
- export interface IntervalWorkerParams {
3
- workerId?: string;
4
- batchCount?: number;
5
- schedule?: WorkerSchedule | string;
6
- }
7
- export declare const scheduleToInterval: (scheduleRaw: WorkerSchedule | string) => number;
8
- export declare const IntervalWorker: IWorker<IntervalWorkerParams>;
9
- //# sourceMappingURL=IntervalWorker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IntervalWorker.d.ts","sourceRoot":"","sources":["../../src/workers/IntervalWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAMzE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,cAAc,GAAG,MAAM,CAAC;CACpC;AAMD,eAAO,MAAM,kBAAkB,gBAAiB,cAAc,GAAG,MAAM,WAMtE,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,oBAAoB,CA+BxD,CAAC"}
@@ -1,38 +0,0 @@
1
- import later from '@breejs/later';
2
- import { BaseWorker } from './BaseWorker.js';
3
- const { NODE_ENV } = process.env;
4
- const defaultSchedule = later.parse.text(NODE_ENV !== 'production' ? 'every 2 seconds' : 'every 30 seconds');
5
- export const scheduleToInterval = (scheduleRaw) => {
6
- const referenceDate = new Date(1000);
7
- const schedule = typeof scheduleRaw === 'string' ? later.parse.text(scheduleRaw) : scheduleRaw;
8
- const [one, two] = later.schedule(schedule).next(2, referenceDate);
9
- const diff = new Date(two).getTime() - new Date(one).getTime();
10
- return Math.min(1000 * 60 * 60, diff); // at least once every hour!
11
- };
12
- export const IntervalWorker = {
13
- ...BaseWorker,
14
- key: 'shop.unchained.worker.cron',
15
- label: 'Allocates work on fixed intervals with native node setInterval',
16
- version: '1.0.0',
17
- type: 'CRON',
18
- actions: ({ workerId, batchCount = 0, schedule = defaultSchedule }, unchainedAPI) => {
19
- const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker }, unchainedAPI);
20
- const intervalDelay = scheduleToInterval(schedule);
21
- let intervalHandle;
22
- return {
23
- ...baseWorkerActions,
24
- start() {
25
- intervalHandle = setInterval(() => {
26
- baseWorkerActions.process({
27
- maxWorkItemCount: batchCount,
28
- referenceDate: IntervalWorker.getFloorDate(),
29
- });
30
- }, intervalDelay);
31
- },
32
- stop() {
33
- clearInterval(intervalHandle);
34
- },
35
- };
36
- },
37
- };
38
- //# sourceMappingURL=IntervalWorker.js.map
@@ -1 +0,0 @@
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,iBAAiB,CAAC;AAE7C,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,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;IACnE,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,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,4BAA4B;AACrE,C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