@unchainedshop/core-worker 3.0.0-alpha2 → 3.0.0-alpha4
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/db/WorkQueueCollection.d.ts +1 -1
- package/lib/db/WorkQueueCollection.d.ts.map +1 -1
- package/lib/director/WorkerAdapter.d.ts +13 -1
- package/lib/director/WorkerAdapter.d.ts.map +1 -1
- package/lib/director/WorkerAdapter.js.map +1 -1
- package/lib/director/WorkerDirector.d.ts +24 -1
- package/lib/director/WorkerDirector.d.ts.map +1 -1
- package/lib/director/WorkerDirector.js +2 -2
- package/lib/director/WorkerDirector.js.map +1 -1
- package/lib/module/configureWorkerModule.d.ts +79 -4
- package/lib/module/configureWorkerModule.d.ts.map +1 -1
- package/lib/module/configureWorkerModule.js +160 -42
- package/lib/module/configureWorkerModule.js.map +1 -1
- package/lib/module/migrations/addMigrations.d.ts +3 -0
- package/lib/module/migrations/addMigrations.d.ts.map +1 -0
- package/lib/module/migrations/addMigrations.js +16 -0
- package/lib/module/migrations/addMigrations.js.map +1 -0
- package/lib/schedulers/FailedRescheduler.d.ts +11 -1
- package/lib/schedulers/FailedRescheduler.d.ts.map +1 -1
- package/lib/schedulers/FailedRescheduler.js.map +1 -1
- package/lib/types.d.ts +20 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/worker-index.d.ts +8 -7
- package/lib/worker-index.d.ts.map +1 -1
- package/lib/worker-index.js +8 -7
- package/lib/worker-index.js.map +1 -1
- package/lib/workers/BaseWorker.d.ts +27 -1
- package/lib/workers/BaseWorker.d.ts.map +1 -1
- package/lib/workers/BaseWorker.js +3 -2
- package/lib/workers/BaseWorker.js.map +1 -1
- package/lib/workers/EventListenerWorker.d.ts +1 -1
- package/lib/workers/EventListenerWorker.d.ts.map +1 -1
- package/lib/workers/EventListenerWorker.js.map +1 -1
- package/lib/workers/IntervalWorker.d.ts +2 -1
- package/lib/workers/IntervalWorker.d.ts.map +1 -1
- package/lib/workers/IntervalWorker.js.map +1 -1
- package/package.json +6 -8
- package/src/db/WorkQueueCollection.ts +1 -1
- package/src/director/WorkerAdapter.ts +15 -1
- package/src/director/WorkerDirector.ts +31 -8
- package/src/module/buildQuerySelector.test.ts +144 -124
- package/src/module/configureWorkerModule.ts +286 -57
- package/src/module/migrations/addMigrations.ts +18 -0
- package/src/schedulers/FailedRescheduler.ts +17 -1
- package/src/types.ts +20 -0
- package/src/worker-index.ts +8 -8
- package/src/workers/BaseWorker.ts +31 -3
- package/src/workers/EventListenerWorker.ts +1 -2
- package/src/workers/IntervalWorker.ts +2 -2
- package/lib/db/WorkQueueSchema.d.ts +0 -3
- package/lib/db/WorkQueueSchema.d.ts.map +0 -1
- package/lib/db/WorkQueueSchema.js +0 -20
- package/lib/db/WorkQueueSchema.js.map +0 -1
- package/src/db/WorkQueueSchema.ts +0 -23
|
@@ -1,189 +1,209 @@
|
|
|
1
|
-
import { WorkStatus } from
|
|
2
|
-
import { buildQuerySelector } from
|
|
3
|
-
|
|
1
|
+
import { WorkStatus } from '../worker-index.js';
|
|
2
|
+
import { buildQuerySelector } from './configureWorkerModule.js';
|
|
4
3
|
|
|
5
4
|
describe('Worker', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
expect(buildQuerySelector({})).toEqual({ deleted: { '$exists': false } })
|
|
5
|
+
describe('buildQuerySelector', () => {
|
|
6
|
+
it('Return correct filter object when passed no argument', () => {
|
|
7
|
+
expect(buildQuerySelector({})).toEqual({ deleted: { $exists: false } });
|
|
10
8
|
});
|
|
11
9
|
|
|
12
|
-
it('Return correct filter object when passed create, queryString, scheduled, status, types & workId',
|
|
13
|
-
const selector = buildQuerySelector({
|
|
10
|
+
it('Return correct filter object when passed create, queryString, scheduled, status, types & workId', () => {
|
|
11
|
+
const selector = buildQuerySelector({
|
|
12
|
+
created: {
|
|
13
|
+
start: new Date('2022-12-04T17:13:09.285Z'),
|
|
14
|
+
end: new Date('2022-12-04T17:13:09.285Z'),
|
|
15
|
+
},
|
|
16
|
+
queryString: 'hello world',
|
|
17
|
+
scheduled: {
|
|
18
|
+
end: new Date('2022-12-04T17:13:09.285Z'),
|
|
19
|
+
start: new Date('2022-12-04T17:13:09.285Z'),
|
|
20
|
+
},
|
|
21
|
+
status: [WorkStatus.ALLOCATED],
|
|
22
|
+
types: ['EMAIL'],
|
|
23
|
+
workId: 'work-id',
|
|
24
|
+
});
|
|
14
25
|
expect(selector).toEqual({
|
|
15
26
|
_id: 'work-id',
|
|
16
|
-
|
|
27
|
+
$or: [
|
|
17
28
|
{
|
|
18
|
-
started: {
|
|
19
|
-
finished: {
|
|
20
|
-
deleted: {
|
|
21
|
-
}
|
|
29
|
+
started: { $exists: true },
|
|
30
|
+
finished: { $exists: false },
|
|
31
|
+
deleted: { $exists: false },
|
|
32
|
+
},
|
|
22
33
|
],
|
|
23
34
|
created: {
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
$gte: new Date('2022-12-04T17:13:09.285Z'),
|
|
36
|
+
$lte: new Date('2022-12-04T17:13:09.285Z'),
|
|
26
37
|
},
|
|
27
38
|
scheduled: {
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
$gte: new Date('2022-12-04T17:13:09.285Z'),
|
|
40
|
+
$lte: new Date('2022-12-04T17:13:09.285Z'),
|
|
30
41
|
},
|
|
31
|
-
type: {
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
)
|
|
35
|
-
|
|
42
|
+
type: { $in: ['EMAIL'] },
|
|
43
|
+
$text: { $search: 'hello world' },
|
|
44
|
+
});
|
|
36
45
|
});
|
|
37
46
|
|
|
38
|
-
it('Return correct filter object when passed queryString, scheduled, status, types & workId',
|
|
39
|
-
const selector = buildQuerySelector({
|
|
47
|
+
it('Return correct filter object when passed queryString, scheduled, status, types & workId', () => {
|
|
48
|
+
const selector = buildQuerySelector({
|
|
49
|
+
queryString: 'hello world',
|
|
50
|
+
scheduled: {
|
|
51
|
+
end: new Date('2022-12-04T17:13:09.285Z'),
|
|
52
|
+
start: new Date('2022-12-04T17:13:09.285Z'),
|
|
53
|
+
},
|
|
54
|
+
status: [WorkStatus.ALLOCATED],
|
|
55
|
+
types: ['EMAIL'],
|
|
56
|
+
workId: 'work-id',
|
|
57
|
+
});
|
|
40
58
|
expect(selector).toEqual({
|
|
41
59
|
_id: 'work-id',
|
|
42
|
-
|
|
60
|
+
$or: [
|
|
43
61
|
{
|
|
44
|
-
started: {
|
|
45
|
-
finished: {
|
|
46
|
-
deleted: {
|
|
47
|
-
}
|
|
62
|
+
started: { $exists: true },
|
|
63
|
+
finished: { $exists: false },
|
|
64
|
+
deleted: { $exists: false },
|
|
65
|
+
},
|
|
48
66
|
],
|
|
49
67
|
scheduled: {
|
|
50
|
-
|
|
51
|
-
|
|
68
|
+
$gte: new Date('2022-12-04T17:13:09.285Z'),
|
|
69
|
+
$lte: new Date('2022-12-04T17:13:09.285Z'),
|
|
52
70
|
},
|
|
53
|
-
type: {
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
)
|
|
57
|
-
|
|
71
|
+
type: { $in: ['EMAIL'] },
|
|
72
|
+
$text: { $search: 'hello world' },
|
|
73
|
+
});
|
|
58
74
|
});
|
|
59
75
|
|
|
60
|
-
it('Return correct filter object when passed scheduled, status, types & workId',
|
|
61
|
-
const selector = buildQuerySelector({
|
|
76
|
+
it('Return correct filter object when passed scheduled, status, types & workId', () => {
|
|
77
|
+
const selector = buildQuerySelector({
|
|
78
|
+
scheduled: {
|
|
79
|
+
end: new Date('2022-12-04T17:13:09.285Z'),
|
|
80
|
+
start: new Date('2022-12-04T17:13:09.285Z'),
|
|
81
|
+
},
|
|
82
|
+
status: [WorkStatus.ALLOCATED],
|
|
83
|
+
types: ['EMAIL'],
|
|
84
|
+
workId: 'work-id',
|
|
85
|
+
});
|
|
62
86
|
expect(selector).toEqual({
|
|
63
87
|
_id: 'work-id',
|
|
64
|
-
|
|
88
|
+
$or: [
|
|
65
89
|
{
|
|
66
|
-
started: {
|
|
67
|
-
finished: {
|
|
68
|
-
deleted: {
|
|
69
|
-
}
|
|
90
|
+
started: { $exists: true },
|
|
91
|
+
finished: { $exists: false },
|
|
92
|
+
deleted: { $exists: false },
|
|
93
|
+
},
|
|
70
94
|
],
|
|
71
95
|
scheduled: {
|
|
72
|
-
|
|
73
|
-
|
|
96
|
+
$gte: new Date('2022-12-04T17:13:09.285Z'),
|
|
97
|
+
$lte: new Date('2022-12-04T17:13:09.285Z'),
|
|
74
98
|
},
|
|
75
|
-
type: {
|
|
76
|
-
}
|
|
77
|
-
)
|
|
78
|
-
|
|
99
|
+
type: { $in: ['EMAIL'] },
|
|
100
|
+
});
|
|
79
101
|
});
|
|
80
102
|
|
|
81
|
-
it('Return correct filter object when passed status, types & workId',
|
|
82
|
-
const selector = buildQuerySelector({
|
|
103
|
+
it('Return correct filter object when passed status, types & workId', () => {
|
|
104
|
+
const selector = buildQuerySelector({
|
|
105
|
+
status: [WorkStatus.ALLOCATED],
|
|
106
|
+
types: ['EMAIL'],
|
|
107
|
+
workId: 'work-id',
|
|
108
|
+
});
|
|
83
109
|
expect(selector).toEqual({
|
|
84
110
|
_id: 'work-id',
|
|
85
|
-
|
|
111
|
+
$or: [
|
|
86
112
|
{
|
|
87
|
-
started: {
|
|
88
|
-
finished: {
|
|
89
|
-
deleted: {
|
|
90
|
-
}
|
|
113
|
+
started: { $exists: true },
|
|
114
|
+
finished: { $exists: false },
|
|
115
|
+
deleted: { $exists: false },
|
|
116
|
+
},
|
|
91
117
|
],
|
|
92
|
-
type: {
|
|
93
|
-
}
|
|
94
|
-
)
|
|
95
|
-
|
|
118
|
+
type: { $in: ['EMAIL'] },
|
|
119
|
+
});
|
|
96
120
|
});
|
|
97
121
|
|
|
98
|
-
it('Return correct filter object when passed types & workId',
|
|
99
|
-
const selector = buildQuerySelector({
|
|
122
|
+
it('Return correct filter object when passed types & workId', () => {
|
|
123
|
+
const selector = buildQuerySelector({ types: ['EMAIL'], workId: 'work-id' });
|
|
100
124
|
expect(selector).toEqual({
|
|
101
125
|
_id: 'work-id',
|
|
102
|
-
deleted: {
|
|
103
|
-
type: {
|
|
104
|
-
}
|
|
105
|
-
)
|
|
106
|
-
|
|
126
|
+
deleted: { $exists: false },
|
|
127
|
+
type: { $in: ['EMAIL'] },
|
|
128
|
+
});
|
|
107
129
|
});
|
|
108
130
|
|
|
109
|
-
it('Return correct filter object when passed workId',
|
|
110
|
-
const selector = buildQuerySelector({
|
|
131
|
+
it('Return correct filter object when passed workId', () => {
|
|
132
|
+
const selector = buildQuerySelector({ workId: 'work-id' });
|
|
111
133
|
expect(selector).toEqual({
|
|
112
134
|
_id: 'work-id',
|
|
113
|
-
deleted: {
|
|
114
|
-
}
|
|
115
|
-
)
|
|
135
|
+
deleted: { $exists: false },
|
|
136
|
+
});
|
|
116
137
|
});
|
|
117
138
|
|
|
118
|
-
it('Create start should be set to start of unix timestamp if created.start not provided',
|
|
119
|
-
const selector = buildQuerySelector({
|
|
120
|
-
|
|
139
|
+
it('Create start should be set to start of unix timestamp if created.start not provided', () => {
|
|
140
|
+
const selector = buildQuerySelector({
|
|
141
|
+
workId: 'work-id',
|
|
142
|
+
created: { end: new Date('2022-12-04T17:13:09.285Z') },
|
|
143
|
+
});
|
|
144
|
+
|
|
121
145
|
expect(selector).toEqual({
|
|
122
146
|
_id: 'work-id',
|
|
123
|
-
deleted: {
|
|
147
|
+
deleted: { $exists: false },
|
|
124
148
|
created: {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
)
|
|
149
|
+
$gte: new Date(0),
|
|
150
|
+
$lte: new Date('2022-12-04T17:13:09.285Z'),
|
|
151
|
+
},
|
|
152
|
+
});
|
|
130
153
|
});
|
|
131
154
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
155
|
+
it('Create start should be set to start or unix timestamp if created.end not provided', () => {
|
|
156
|
+
const selector = buildQuerySelector({
|
|
157
|
+
workId: 'work-id',
|
|
158
|
+
created: { start: new Date('2022-12-04T17:13:09.285Z') },
|
|
159
|
+
});
|
|
135
160
|
|
|
136
161
|
expect(selector).toEqual({
|
|
137
162
|
_id: 'work-id',
|
|
138
|
-
deleted: {
|
|
139
|
-
created: {
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
)
|
|
163
|
+
deleted: { $exists: false },
|
|
164
|
+
created: { $gte: new Date('2022-12-04T17:13:09.285Z') },
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
expect(buildQuerySelector({ workId: 'work-id', created: {} })).toEqual({
|
|
168
|
+
_id: 'work-id',
|
|
169
|
+
deleted: { $exists: false },
|
|
170
|
+
created: { $gte: new Date(0) },
|
|
171
|
+
});
|
|
149
172
|
});
|
|
150
173
|
|
|
174
|
+
it('scheduled start should be set to start of unix timestamp if scheduled.start not provided', () => {
|
|
175
|
+
const selector = buildQuerySelector({
|
|
176
|
+
workId: 'work-id',
|
|
177
|
+
scheduled: { end: new Date('2022-12-04T17:13:09.285Z') },
|
|
178
|
+
});
|
|
151
179
|
|
|
152
|
-
it('scheduled start should be set to start of unix timestamp if scheduled.start not provided', async () => {
|
|
153
|
-
const selector = buildQuerySelector({ workId: 'work-id', scheduled: {end: new Date("2022-12-04T17:13:09.285Z")}})
|
|
154
|
-
|
|
155
180
|
expect(selector).toEqual({
|
|
156
181
|
_id: 'work-id',
|
|
157
|
-
deleted: {
|
|
182
|
+
deleted: { $exists: false },
|
|
158
183
|
scheduled: {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
)
|
|
184
|
+
$gte: new Date(0),
|
|
185
|
+
$lte: new Date('2022-12-04T17:13:09.285Z'),
|
|
186
|
+
},
|
|
187
|
+
});
|
|
164
188
|
});
|
|
165
189
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
190
|
+
it('Scheduled start should be set to start or unix timestamp if scheduled.end not provided', () => {
|
|
191
|
+
const selector = buildQuerySelector({
|
|
192
|
+
workId: 'work-id',
|
|
193
|
+
scheduled: { start: new Date('2022-12-04T17:13:09.285Z') },
|
|
194
|
+
});
|
|
169
195
|
|
|
170
196
|
expect(selector).toEqual({
|
|
171
197
|
_id: 'work-id',
|
|
172
|
-
deleted: {
|
|
173
|
-
scheduled: {
|
|
174
|
-
}
|
|
175
|
-
)
|
|
176
|
-
|
|
177
|
-
expect(buildQuerySelector({ workId: 'work-id', scheduled: {}})).toEqual({
|
|
178
|
-
_id: 'work-id',
|
|
179
|
-
deleted: { '$exists': false },
|
|
180
|
-
scheduled: { '$gte': new Date(0)}
|
|
181
|
-
}
|
|
182
|
-
)
|
|
183
|
-
});
|
|
184
|
-
|
|
198
|
+
deleted: { $exists: false },
|
|
199
|
+
scheduled: { $gte: new Date('2022-12-04T17:13:09.285Z') },
|
|
200
|
+
});
|
|
185
201
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
202
|
+
expect(buildQuerySelector({ workId: 'work-id', scheduled: {} })).toEqual({
|
|
203
|
+
_id: 'work-id',
|
|
204
|
+
deleted: { $exists: false },
|
|
205
|
+
scheduled: { $gte: new Date(0) },
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
189
209
|
});
|