@or-sdk/contacts 4.0.2-beta.2357.0 → 4.0.2-beta.2364.0
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/README.md +0 -37
- package/dist/cjs/api/baseWithPolingApi.js +12 -28
- package/dist/cjs/api/baseWithPolingApi.js.map +1 -1
- package/dist/cjs/api/bulkContactsCreateApi.js +123 -152
- package/dist/cjs/api/bulkContactsCreateApi.js.map +1 -1
- package/dist/cjs/constants.js +2 -3
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/utils.js +2 -10
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/api/baseWithPolingApi.js +7 -15
- package/dist/esm/api/baseWithPolingApi.js.map +1 -1
- package/dist/esm/api/bulkContactsCreateApi.js +54 -82
- package/dist/esm/api/bulkContactsCreateApi.js.map +1 -1
- package/dist/esm/constants.js +1 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/utils.js +1 -7
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/api/baseWithPolingApi.d.ts +1 -4
- package/dist/types/api/baseWithPolingApi.d.ts.map +1 -1
- package/dist/types/api/bulkContactsCreateApi.d.ts +2 -2
- package/dist/types/api/bulkContactsCreateApi.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -2
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/types.d.ts +1 -9
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +0 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/api/baseWithPolingApi.ts +7 -22
- package/src/api/bulkContactsCreateApi.ts +64 -141
- package/src/constants.ts +1 -3
- package/src/types.ts +1 -9
- package/src/utils.ts +1 -8
package/README.md
CHANGED
|
@@ -100,41 +100,4 @@ for await (const bulkResults of bulkCreateApi.trackBulkCreateContacts('bulkName'
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
```
|
|
103
|
-
|
|
104
|
-
## Tuning bulk
|
|
105
|
-
|
|
106
|
-
Create bulk consumes lots of resources, in terms of the quantity of launched lambdas (it's huge!), and in terms of created workload on the DB (DB server memory, CPU, connections to the DB).
|
|
107
|
-
So basically it means that the more activities are taking place at particular point of time the higher is the probability of bulk failure. It is strongly recommended to execute the bulk create operation during non working hours!
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
Bulk provides some interface for tuning the workload by means of the `options` argument. With the default options, the bulk successfully completes 200k contacts for approximately 5 mins. Tuning options may result into the bulk operation performance degrade, however it might dramatically reduce workload on the system and turn failed bulk into successful one!
|
|
111
|
-
|
|
112
|
-
Here is the short description of the bulk create contacts mechanism to understand how to affect it by tuning options:
|
|
113
|
-
- bulk examines the size of passed data and if it is more that 4000000 bytes the data is broken into array of data with the same type, however each element of this array is less than the allowed batchSize; each element of this array is called `batch`
|
|
114
|
-
- bulk executes 4 (by default, might be tuned with the `parallelBatchesAmount`) batches in parallel - we call it `batches series`; **executing** here means sending the batch data to the server where contacts, actually, are created and inserted into DB
|
|
115
|
-
- batch execution duration can't be determined and to avoid the gateway timeout error the execution results are poled. Every poling attempt are repeated in the amount of time specified by `polingDuration`
|
|
116
|
-
- if batches series fails (it might happen due to DB server overload, for example), one more attempt is made after the amount of time specified with `repeatFailedParallelBatchesIn`
|
|
117
|
-
- when all batches are executed, bulk results is formed
|
|
118
|
-
|
|
119
|
-
Here is the options:
|
|
120
|
-
```js
|
|
121
|
-
{
|
|
122
|
-
|
|
123
|
-
batchSize?: number; // default is 4000000 bytes.
|
|
124
|
-
// Reducing this number is the very first step you should try.
|
|
125
|
-
parallelBatchesAmount?: number; // default is 4. Reducing it also improves bulk reliability,
|
|
126
|
-
// however it is making it slower.
|
|
127
|
-
batchesToProcess?: number; // default is ALL batches. If specified, executes only the number
|
|
128
|
-
//of batches passed here.
|
|
129
|
-
polingDuration?: number; // default is 15000 milliseconds,
|
|
130
|
-
//specifies the pause duration between poling batch process results
|
|
131
|
-
repeatFailedParallelBatchesIn?: number; // default is 30000 milliseconds (30 seconds) -
|
|
132
|
-
// the amount of time bulk waits until repeating an attempt
|
|
133
|
-
// to execute again a failed series of batches
|
|
134
|
-
logger?: BulkLogger; // logger, pass here an object that has log() function;
|
|
135
|
-
// to be more precise, the log function should be of the following type:
|
|
136
|
-
// (message?: unknown, ...optionalParams: unknown[]) => void
|
|
137
|
-
};
|
|
138
|
-
```
|
|
139
|
-
|
|
140
103
|
|
|
@@ -64,45 +64,29 @@ var BaseWithPoling = (function (_super) {
|
|
|
64
64
|
_this.batchProcessApi = batchProcessApi;
|
|
65
65
|
return _this;
|
|
66
66
|
}
|
|
67
|
-
BaseWithPoling.prototype.
|
|
68
|
-
this.logger = logger;
|
|
69
|
-
};
|
|
70
|
-
BaseWithPoling.prototype.polling = function (batchId, polingDuration, repeats) {
|
|
71
|
-
var _a;
|
|
72
|
-
if (polingDuration === void 0) { polingDuration = constants_1.BULK_POLING_PAUSE_DURATION; }
|
|
67
|
+
BaseWithPoling.prototype.polling = function (batchId, repeats) {
|
|
73
68
|
if (repeats === void 0) { repeats = 0; }
|
|
74
69
|
return __awaiter(this, void 0, void 0, function () {
|
|
75
70
|
var batchProcess, e_1;
|
|
76
71
|
var _this = this;
|
|
77
|
-
return __generator(this, function (
|
|
78
|
-
switch (
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
switch (_a.label) {
|
|
79
74
|
case 0:
|
|
80
|
-
|
|
81
|
-
return [4, (0, utils_1.debouncePromise)(function () { return _this.batchProcessApi.getBatchProcess(batchId); },
|
|
75
|
+
_a.trys.push([0, 2, , 5]);
|
|
76
|
+
return [4, (0, utils_1.debouncePromise)(function () { return _this.batchProcessApi.getBatchProcess(batchId); }, 1000)];
|
|
82
77
|
case 1:
|
|
83
|
-
batchProcess =
|
|
78
|
+
batchProcess = _a.sent();
|
|
84
79
|
return [3, 5];
|
|
85
80
|
case 2:
|
|
86
|
-
e_1 =
|
|
81
|
+
e_1 = _a.sent();
|
|
87
82
|
if (!(repeats < constants_1.FAILED_REQUEST_REPEATS
|
|
88
83
|
&& 'statusCode' in e_1
|
|
89
|
-
&& e_1.statusCode ===
|
|
90
|
-
(
|
|
91
|
-
|
|
92
|
-
var result;
|
|
93
|
-
return __generator(this, function (_a) {
|
|
94
|
-
switch (_a.label) {
|
|
95
|
-
case 0: return [4, this.polling(batchId, polingDuration, repeats + 1)];
|
|
96
|
-
case 1:
|
|
97
|
-
result = _a.sent();
|
|
98
|
-
return [2, result];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}); }, (repeats + 1) * polingDuration)];
|
|
102
|
-
case 3: return [2, _b.sent()];
|
|
84
|
+
&& e_1.statusCode === 410)) return [3, 4];
|
|
85
|
+
return [4, (0, utils_1.debouncePromise)(function () { return _this.polling(batchId, repeats + 1); }, 2000)];
|
|
86
|
+
case 3: return [2, _a.sent()];
|
|
103
87
|
case 4:
|
|
104
88
|
if (repeats < constants_1.FAILED_REQUEST_REPEATS) {
|
|
105
|
-
return [2, this.polling(batchId,
|
|
89
|
+
return [2, this.polling(batchId, repeats + 1)];
|
|
106
90
|
}
|
|
107
91
|
throw new apiError_1.CreateContactsBatchError(e_1.message, batchId);
|
|
108
92
|
case 5:
|
|
@@ -110,7 +94,7 @@ var BaseWithPoling = (function (_super) {
|
|
|
110
94
|
throw new apiError_1.CreateContactsBatchError('Could not complete batch process', batchId, batchProcess.messages);
|
|
111
95
|
}
|
|
112
96
|
return [2, batchProcess.status === types_contacts_api_1.BatchProcessStatus.pending
|
|
113
|
-
? this.polling(batchId
|
|
97
|
+
? this.polling(batchId)
|
|
114
98
|
: batchProcess];
|
|
115
99
|
}
|
|
116
100
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseWithPolingApi.js","sourceRoot":"","sources":["../../../src/api/baseWithPolingApi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qCAAoC;AAEpC,mEAA2F;AA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,EAAE;4BACrD,MAAM,IAAI,mCAAwB,CAChC,kCAAkC,EAClC,OAAO,EACP,YAAY,CAAC,QAAQ,CACtB,CAAC;yBACH;wBAED,WAAO,YAAY,CAAC,MAAM,KAAK,uCAAkB,CAAC,OAAO;gCACvD,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;gCACvB,CAAC,CAAC,YAAY,EAAC;;;;KAClB;IACH,qBAAC;AAAD,CAAC,AA1CD,CAA4C,iBAAO,GA0ClD"}
|
|
@@ -153,89 +153,73 @@ var BulkContactsCreateApi = (function (_super) {
|
|
|
153
153
|
});
|
|
154
154
|
});
|
|
155
155
|
};
|
|
156
|
-
BulkContactsCreateApi.prototype.logBulkDetails = function (size, totalContacts, totalBatches, options) {
|
|
157
|
-
options.logger.log('data size = ', size, ' bytes');
|
|
158
|
-
options.logger.log('total contacts = ', totalContacts);
|
|
159
|
-
options.logger.log('batches amount = ', totalBatches);
|
|
160
|
-
options.logger.log('average batch size ~ ', Math.ceil(totalContacts / totalBatches), ' contacts');
|
|
161
|
-
options.logger.log('parallel batches size = ', options.parallelBatchesAmount || constants_1.MAX_PARALLEL_BATCH_PROCESSING);
|
|
162
|
-
options.logger.log('batch size = ', options.batchSize || constants_1.REQUEST_PAYLOAD_MAX_BYTES, ' bytes');
|
|
163
|
-
};
|
|
164
156
|
BulkContactsCreateApi.prototype.trackBulkCreateContacts = function (bulkName, data, options) {
|
|
165
|
-
var _a, _b;
|
|
166
157
|
if (options === void 0) { options = {}; }
|
|
167
158
|
return __asyncGenerator(this, arguments, function trackBulkCreateContacts_1() {
|
|
168
|
-
var
|
|
169
|
-
var e_2,
|
|
170
|
-
return __generator(this, function (
|
|
171
|
-
switch (
|
|
159
|
+
var dataWithContactKeys, contacts, rest, contactsMaxSize, contactsChunks, _a, _b, progress, e_2_1, results;
|
|
160
|
+
var e_2, _c;
|
|
161
|
+
return __generator(this, function (_d) {
|
|
162
|
+
switch (_d.label) {
|
|
172
163
|
case 0:
|
|
173
|
-
this.setLogger(options.logger);
|
|
174
|
-
(_a = options.logger) === null || _a === void 0 ? void 0 : _a.log('Starting ', bulkName, ' bulk');
|
|
175
|
-
startTime = performance.now();
|
|
176
164
|
dataWithContactKeys = this.updateContactsWithContactKeys(data);
|
|
165
|
+
_d.label = 1;
|
|
166
|
+
case 1:
|
|
167
|
+
_d.trys.push([1, , 17, 18]);
|
|
177
168
|
contacts = dataWithContactKeys.contacts, rest = __rest(dataWithContactKeys, ["contacts"]);
|
|
178
169
|
contactsMaxSize = options.batchSize || constants_1.REQUEST_PAYLOAD_MAX_BYTES - (0, utils_1.getObjectSizeInBytes)(__assign({}, rest));
|
|
179
170
|
contactsChunks = (0, utils_1.chunkArrByMaxSize)(contacts, contactsMaxSize);
|
|
180
|
-
if (options.
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
_f.label = 1;
|
|
184
|
-
case 1:
|
|
185
|
-
_f.trys.push([1, , 19, 20]);
|
|
186
|
-
if (!(contactsChunks.length === 1 || options.batchesToProcess === 1)) return [3, 5];
|
|
187
|
-
return [4, __await(this.createContactsInSingleBatch(bulkName, __assign(__assign({}, dataWithContactKeys), { batchIdx: 0 }), options))];
|
|
171
|
+
if (!(contactsChunks.length === 1 || options.batchesToProcess === 1)) return [3, 3];
|
|
172
|
+
return [4, __await(this.createContactsInSingleBatch(dataWithContactKeys, bulkName))];
|
|
188
173
|
case 2:
|
|
189
|
-
|
|
174
|
+
_d.sent();
|
|
175
|
+
return [3, 16];
|
|
176
|
+
case 3:
|
|
177
|
+
_d.trys.push([3, 10, 11, 16]);
|
|
178
|
+
_a = __asyncValues(this.createContactsInMultiBatches(contactsChunks, rest, bulkName, options));
|
|
179
|
+
_d.label = 4;
|
|
180
|
+
case 4: return [4, __await(_a.next())];
|
|
181
|
+
case 5:
|
|
182
|
+
if (!(_b = _d.sent(), !_b.done)) return [3, 9];
|
|
183
|
+
progress = _b.value;
|
|
190
184
|
return [4, __await({
|
|
191
|
-
type: '
|
|
192
|
-
results:
|
|
193
|
-
created: {},
|
|
194
|
-
failed: {},
|
|
195
|
-
}, [results]),
|
|
185
|
+
type: 'progress',
|
|
186
|
+
results: progress,
|
|
196
187
|
})];
|
|
197
|
-
case
|
|
198
|
-
case 4:
|
|
199
|
-
_f.sent();
|
|
200
|
-
return [3, 18];
|
|
201
|
-
case 5:
|
|
202
|
-
_f.trys.push([5, 12, 13, 18]);
|
|
203
|
-
_c = __asyncValues(this.createContactsInMultiBatches(contactsChunks, rest, bulkName, options));
|
|
204
|
-
_f.label = 6;
|
|
205
|
-
case 6: return [4, __await(_c.next())];
|
|
188
|
+
case 6: return [4, _d.sent()];
|
|
206
189
|
case 7:
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
return [4, __await(results)];
|
|
214
|
-
case 8: return [4, _f.sent()];
|
|
215
|
-
case 9:
|
|
216
|
-
_f.sent();
|
|
217
|
-
_f.label = 10;
|
|
218
|
-
case 10: return [3, 6];
|
|
219
|
-
case 11: return [3, 18];
|
|
220
|
-
case 12:
|
|
221
|
-
e_2_1 = _f.sent();
|
|
190
|
+
_d.sent();
|
|
191
|
+
_d.label = 8;
|
|
192
|
+
case 8: return [3, 4];
|
|
193
|
+
case 9: return [3, 16];
|
|
194
|
+
case 10:
|
|
195
|
+
e_2_1 = _d.sent();
|
|
222
196
|
e_2 = { error: e_2_1 };
|
|
223
|
-
return [3,
|
|
224
|
-
case
|
|
225
|
-
|
|
226
|
-
if (!(
|
|
227
|
-
return [4, __await(
|
|
197
|
+
return [3, 16];
|
|
198
|
+
case 11:
|
|
199
|
+
_d.trys.push([11, , 14, 15]);
|
|
200
|
+
if (!(_b && !_b.done && (_c = _a.return))) return [3, 13];
|
|
201
|
+
return [4, __await(_c.call(_a))];
|
|
202
|
+
case 12:
|
|
203
|
+
_d.sent();
|
|
204
|
+
_d.label = 13;
|
|
205
|
+
case 13: return [3, 15];
|
|
228
206
|
case 14:
|
|
229
|
-
_f.sent();
|
|
230
|
-
_f.label = 15;
|
|
231
|
-
case 15: return [3, 17];
|
|
232
|
-
case 16:
|
|
233
207
|
if (e_2) throw e_2.error;
|
|
234
208
|
return [7];
|
|
209
|
+
case 15: return [7];
|
|
210
|
+
case 16: return [3, 18];
|
|
235
211
|
case 17: return [7];
|
|
236
|
-
case 18: return [
|
|
237
|
-
case 19:
|
|
238
|
-
|
|
212
|
+
case 18: return [4, __await(this.getBulkCreateResults(bulkName, options))];
|
|
213
|
+
case 19:
|
|
214
|
+
results = _d.sent();
|
|
215
|
+
return [4, __await({
|
|
216
|
+
type: 'results',
|
|
217
|
+
results: results,
|
|
218
|
+
})];
|
|
219
|
+
case 20: return [4, _d.sent()];
|
|
220
|
+
case 21:
|
|
221
|
+
_d.sent();
|
|
222
|
+
return [2];
|
|
239
223
|
}
|
|
240
224
|
});
|
|
241
225
|
});
|
|
@@ -300,123 +284,110 @@ var BulkContactsCreateApi = (function (_super) {
|
|
|
300
284
|
}
|
|
301
285
|
});
|
|
302
286
|
};
|
|
303
|
-
BulkContactsCreateApi.prototype.
|
|
304
|
-
var _a;
|
|
287
|
+
BulkContactsCreateApi.prototype.getBulkCreateResults = function (batchGroupId, options) {
|
|
305
288
|
return __awaiter(this, void 0, void 0, function () {
|
|
306
|
-
var
|
|
307
|
-
var _this = this;
|
|
289
|
+
var _a, total, firstResults, size, results, pageSize, i, nextResults;
|
|
308
290
|
return __generator(this, function (_b) {
|
|
309
291
|
switch (_b.label) {
|
|
292
|
+
case 0: return [4, this.callGetBulkResults(batchGroupId, 0)];
|
|
293
|
+
case 1:
|
|
294
|
+
_a = _b.sent(), total = _a.total, firstResults = _a.results, size = _a.size;
|
|
295
|
+
results = __assign({}, firstResults);
|
|
296
|
+
pageSize = options.bulkResultsPageSize || constants_1.BULK_RESULT_PAGE_SIZE;
|
|
297
|
+
if (!(total > size)) return [3, 5];
|
|
298
|
+
i = 1;
|
|
299
|
+
_b.label = 2;
|
|
300
|
+
case 2:
|
|
301
|
+
if (!(i <= Math.ceil((total - size) / size))) return [3, 5];
|
|
302
|
+
return [4, this.callGetBulkResults(batchGroupId, i * pageSize)];
|
|
303
|
+
case 3:
|
|
304
|
+
nextResults = (_b.sent()).results;
|
|
305
|
+
results = {
|
|
306
|
+
created: __assign(__assign({}, results.created), nextResults.created),
|
|
307
|
+
failed: __assign(__assign({}, results.failed), nextResults.created),
|
|
308
|
+
};
|
|
309
|
+
_b.label = 4;
|
|
310
|
+
case 4:
|
|
311
|
+
i++;
|
|
312
|
+
return [3, 2];
|
|
313
|
+
case 5: return [2, results];
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
BulkContactsCreateApi.prototype.callGetBulkResults = function (batchGroupId, skip) {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
320
|
+
return __generator(this, function (_a) {
|
|
321
|
+
return [2, this.apiCall({
|
|
322
|
+
method: 'GET',
|
|
323
|
+
route: "".concat(this.apiBasePath, "/bulk-results/").concat(batchGroupId, "/").concat(skip),
|
|
324
|
+
})];
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
BulkContactsCreateApi.prototype.createContactsInSingleBatch = function (data, batchGroupId) {
|
|
329
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
330
|
+
var batchId;
|
|
331
|
+
var _this = this;
|
|
332
|
+
return __generator(this, function (_a) {
|
|
333
|
+
switch (_a.label) {
|
|
310
334
|
case 0:
|
|
311
335
|
batchId = (0, uuid_1.v4)();
|
|
312
|
-
batchIdx = singleBatchData.batchIdx, data = __rest(singleBatchData, ["batchIdx"]);
|
|
313
336
|
this.apiCall({
|
|
314
337
|
method: 'POST',
|
|
315
338
|
route: "".concat(this.apiBasePath, "/bulk"),
|
|
316
339
|
data: __assign(__assign({}, data), { batchId: batchId, batchGroupId: batchGroupId }),
|
|
317
340
|
});
|
|
318
|
-
return [4, (0, utils_1.debouncePromise)(function () { return _this.polling(batchId
|
|
341
|
+
return [4, (0, utils_1.debouncePromise)(function () { return _this.polling(batchId); }, 3000)];
|
|
319
342
|
case 1:
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return [2, batch];
|
|
343
|
+
_a.sent();
|
|
344
|
+
return [2];
|
|
323
345
|
}
|
|
324
346
|
});
|
|
325
347
|
});
|
|
326
348
|
};
|
|
327
|
-
BulkContactsCreateApi.prototype.mergeResults = function (current, batchProcesses) {
|
|
328
|
-
return batchProcesses.reduce(function (acc, batch) {
|
|
329
|
-
var createdContacts = batch.results.reduce(function (acc, result) { return (0, utils_1.mergeObjects)(acc, JSON.parse(result)); }, {});
|
|
330
|
-
var failedContacts = batch.messages.reduce(function (acc, message) { return (0, utils_1.mergeObjects)(acc, JSON.parse(message)); }, {});
|
|
331
|
-
return {
|
|
332
|
-
created: __assign(__assign({}, acc.created), createdContacts),
|
|
333
|
-
failed: __assign(__assign({}, acc.failed), failedContacts),
|
|
334
|
-
};
|
|
335
|
-
}, current);
|
|
336
|
-
};
|
|
337
349
|
BulkContactsCreateApi.prototype.createContactsInMultiBatches = function (contactsBatches, data, batchGroupId, options) {
|
|
338
|
-
var _a;
|
|
339
350
|
return __asyncGenerator(this, arguments, function createContactsInMultiBatches_1() {
|
|
340
|
-
var
|
|
351
|
+
var batchPromises, parallelBatchesAmount, progress, i, batch;
|
|
341
352
|
var _this = this;
|
|
342
|
-
return __generator(this, function (
|
|
343
|
-
switch (
|
|
353
|
+
return __generator(this, function (_a) {
|
|
354
|
+
switch (_a.label) {
|
|
344
355
|
case 0:
|
|
345
|
-
repeatIn = options.repeatFailedParallelBatchesIn || constants_1.BULK_FAILED_SERIES_REPEAT_IN;
|
|
346
356
|
batchPromises = contactsBatches
|
|
347
|
-
.map(function (chunkContacts
|
|
357
|
+
.map(function (chunkContacts) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
358
|
+
return __generator(this, function (_a) {
|
|
359
|
+
return [2, this.createContactsInSingleBatch(__assign({ contacts: chunkContacts }, data), batchGroupId)];
|
|
360
|
+
});
|
|
361
|
+
}); }; });
|
|
362
|
+
parallelBatchesAmount = options.parallelBatchesAmount || constants_1.MAX_PARALLEL_BATCH_PROCESSING;
|
|
348
363
|
progress = {
|
|
349
364
|
totalBatches: contactsBatches.length,
|
|
350
365
|
totalContacts: contactsBatches.map(function (b) { return b.length; }).reduce(function (acc, curr) { return acc + curr; }, 0),
|
|
351
366
|
completedBatches: 0,
|
|
352
367
|
completedContacts: 0,
|
|
353
368
|
};
|
|
354
|
-
results = {
|
|
355
|
-
created: {},
|
|
356
|
-
failed: {},
|
|
357
|
-
};
|
|
358
|
-
parallelBatchesAmount = options.parallelBatchesAmount || constants_1.MAX_PARALLEL_BATCH_PROCESSING;
|
|
359
|
-
_loop_1 = function (i) {
|
|
360
|
-
var startIdx, endIdx, batchesSeries, seriesResults, e_3;
|
|
361
|
-
return __generator(this, function (_c) {
|
|
362
|
-
switch (_c.label) {
|
|
363
|
-
case 0:
|
|
364
|
-
startIdx = i;
|
|
365
|
-
endIdx = i + parallelBatchesAmount;
|
|
366
|
-
batchesSeries = batchPromises.slice(i, i + parallelBatchesAmount);
|
|
367
|
-
seriesResults = [];
|
|
368
|
-
_c.label = 1;
|
|
369
|
-
case 1:
|
|
370
|
-
_c.trys.push([1, 3, , 5]);
|
|
371
|
-
return [4, __await(Promise.all(batchesSeries.map(function (p) { return p(); })))];
|
|
372
|
-
case 2:
|
|
373
|
-
seriesResults = _c.sent();
|
|
374
|
-
return [3, 5];
|
|
375
|
-
case 3:
|
|
376
|
-
e_3 = _c.sent();
|
|
377
|
-
(_a = options.logger) === null || _a === void 0 ? void 0 : _a.log("Failed to execute of ".concat(parallelBatchesAmount, " batches, from ").concat(startIdx, " to ").concat(endIdx, ", repeating attempt..."));
|
|
378
|
-
return [4, __await((0, utils_1.debouncePromise)(function () { return Promise.all(batchesSeries.map(function (p) { return p(); })); }, repeatIn))];
|
|
379
|
-
case 4:
|
|
380
|
-
seriesResults = _c.sent();
|
|
381
|
-
return [3, 5];
|
|
382
|
-
case 5:
|
|
383
|
-
results = this_1.mergeResults(results, seriesResults);
|
|
384
|
-
progress.completedBatches += batchesSeries.length;
|
|
385
|
-
progress.completedContacts += contactsBatches
|
|
386
|
-
.slice(i, i + parallelBatchesAmount)
|
|
387
|
-
.map(function (batch) { return batch.length; })
|
|
388
|
-
.reduce(function (acc, curr) { return acc + curr; }, 0);
|
|
389
|
-
return [4, __await({
|
|
390
|
-
type: 'progress',
|
|
391
|
-
results: progress,
|
|
392
|
-
})];
|
|
393
|
-
case 6: return [4, _c.sent()];
|
|
394
|
-
case 7:
|
|
395
|
-
_c.sent();
|
|
396
|
-
return [2];
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
};
|
|
400
|
-
this_1 = this;
|
|
401
369
|
i = 0;
|
|
402
|
-
|
|
370
|
+
_a.label = 1;
|
|
403
371
|
case 1:
|
|
404
|
-
if (!(i < (options.batchesToProcess || batchPromises.length))) return [3,
|
|
405
|
-
|
|
372
|
+
if (!(i < (options.batchesToProcess || batchPromises.length))) return [3, 6];
|
|
373
|
+
batch = batchPromises.slice(i, i + parallelBatchesAmount);
|
|
374
|
+
return [4, __await(Promise.all(batch.map(function (p) { return p(); })))];
|
|
406
375
|
case 2:
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
376
|
+
_a.sent();
|
|
377
|
+
progress.completedBatches += batch.length;
|
|
378
|
+
progress.completedContacts += contactsBatches
|
|
379
|
+
.slice(i, i + parallelBatchesAmount)
|
|
380
|
+
.map(function (batch) { return batch.length; })
|
|
381
|
+
.reduce(function (acc, curr) { return acc + curr; }, 0);
|
|
382
|
+
return [4, __await(progress)];
|
|
383
|
+
case 3: return [4, _a.sent()];
|
|
384
|
+
case 4:
|
|
385
|
+
_a.sent();
|
|
386
|
+
_a.label = 5;
|
|
387
|
+
case 5:
|
|
410
388
|
i += parallelBatchesAmount;
|
|
411
389
|
return [3, 1];
|
|
412
|
-
case
|
|
413
|
-
type: 'results',
|
|
414
|
-
results: results,
|
|
415
|
-
})];
|
|
416
|
-
case 5: return [4, _b.sent()];
|
|
417
|
-
case 6:
|
|
418
|
-
_b.sent();
|
|
419
|
-
return [2];
|
|
390
|
+
case 6: return [2];
|
|
420
391
|
}
|
|
421
392
|
});
|
|
422
393
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulkContactsCreateApi.js","sourceRoot":"","sources":["../../../src/api/bulkContactsCreateApi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0EAAiD;AAEjD,
|
|
1
|
+
{"version":3,"file":"bulkContactsCreateApi.js","sourceRoot":"","sources":["../../../src/api/bulkContactsCreateApi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0EAAiD;AAEjD,0CAA+G;AAC/G,kCAAoF;AACpF,6BAA0B;AAQ1B;IAAmD,yCAAc;IAC/D,+BACqB,OAAgD,EACzD,eAAgC;QAF5C,YAIE,kBAAM,OAAO,EAAE,eAAe,CAAC,SAChC;QAJoB,aAAO,GAAP,OAAO,CAAyC;QACzD,qBAAe,GAAf,eAAe,CAAiB;QAK3B,iBAAW,GAAG,aAAa,CAAC;;IAF7C,CAAC;IAmCY,kDAAkB,GAA/B,UACE,QAAgB,EAChB,IAAoB,EACpB,OAAyB;;QAAzB,wBAAA,EAAA,YAAyB;;;;;;;wBAEa,KAAA,cAAA,IAAI,CAAC,uBAAuB,CAChE,QAAQ,EACR,IAAI,EACJ,OAAO,CACR,CAAA;;;;;wBAJgB,aAAiB,EAAf,IAAI,UAAA,EAAE,OAAO,aAAA,CAAE;wBAKhC,IAAI,IAAI,KAA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AAE,CAAC;yBACrB,CAAC;wBAEO,CAAC,GAAG,CAAC;;;6BAAC,CAAA,CAAC,GAAG,CAAC,OAAO,CAAC,gBAAgB,IAAI,aAAa,CAAC,MAAM,CAAC,CAAA;wBAC7D,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,qBAAqB,CAAC,CAAC;wBAChE,mBAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,EAAE,EAAH,CAAG,CAAC,CAAC,GAAA;;wBAAxC,SAAwC,CAAC;wBACzC,QAAQ,CAAC,gBAAgB,IAAI,KAAK,CAAC,MAAM,CAAC;wBAC1C,QAAQ,CAAC,iBAAiB,IAAI,eAAe;6BAC1C,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,qBAAqB,CAAC;6BACnC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,MAAM,EAAZ,CAAY,CAAC;6BAC1B,MAAM,CAAC,UAAC,GAAG,EAAE,IAAI,IAAK,OAAA,GAAG,GAAG,IAAI,EAAV,CAAU,EAAE,CAAC,CAAC,CAAC;2CAClC,QAAQ;4BAAd,sBAAc;;wBAAd,SAAc,CAAC;;;wBARqD,CAAC,IAAI,qBAAqB,CAAA;;;;;;KAUjG;IAEH,4BAAC;AAAD,CAAC,AAnOD,CAAmD,2BAAc,GAmOhE"}
|
package/dist/cjs/constants.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.BULK_RESULT_PAGE_SIZE = exports.CONTACTS_DELETE_MAX_AMOUNT = exports.FAILED_REQUEST_REPEATS = exports.MAX_PARALLEL_BATCH_PROCESSING = exports.REQUEST_PAYLOAD_MAX_BYTES = exports.CONTACTS_SERVICE_KEY = void 0;
|
|
4
4
|
exports.CONTACTS_SERVICE_KEY = 'contacts-api';
|
|
5
5
|
exports.REQUEST_PAYLOAD_MAX_BYTES = 4000000;
|
|
6
6
|
exports.MAX_PARALLEL_BATCH_PROCESSING = 4;
|
|
7
7
|
exports.FAILED_REQUEST_REPEATS = 3;
|
|
8
8
|
exports.CONTACTS_DELETE_MAX_AMOUNT = 1000;
|
|
9
|
-
exports.
|
|
10
|
-
exports.BULK_FAILED_SERIES_REPEAT_IN = 30000;
|
|
9
|
+
exports.BULK_RESULT_PAGE_SIZE = 300;
|
|
11
10
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,cAAc,CAAC;AAEtC,QAAA,yBAAyB,GAAG,OAAO,CAAC;AAEpC,QAAA,6BAA6B,GAAG,CAAC,CAAC;AAElC,QAAA,sBAAsB,GAAG,CAAC,CAAC;AAE3B,QAAA,0BAA0B,GAAG,IAAI,CAAC;AAElC,QAAA,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,cAAc,CAAC;AAEtC,QAAA,yBAAyB,GAAG,OAAO,CAAC;AAEpC,QAAA,6BAA6B,GAAG,CAAC,CAAC;AAElC,QAAA,sBAAsB,GAAG,CAAC,CAAC;AAE3B,QAAA,0BAA0B,GAAG,IAAI,CAAC;AAElC,QAAA,qBAAqB,GAAG,GAAG,CAAC"}
|
package/dist/cjs/utils.js
CHANGED
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.buildHttpAgents = exports.debouncePromise = exports.chunkArrByMaxSize = exports.getObjectSizeInBytes = exports.adaptListParams = void 0;
|
|
18
18
|
var agentkeepalive_1 = __importDefault(require("agentkeepalive"));
|
|
19
19
|
var propertyToEscape = ['from', 'size', 'orderProperty', 'orderDirection'];
|
|
20
20
|
var adaptListParams = function (params) {
|
|
@@ -63,7 +63,7 @@ var chunkArrByMaxSize = function (arr, maxSize) {
|
|
|
63
63
|
if (chunksLength < arr.length) {
|
|
64
64
|
chunks[chunkIdx + 1] = arr.slice(chunksLength);
|
|
65
65
|
}
|
|
66
|
-
return chunks
|
|
66
|
+
return chunks;
|
|
67
67
|
};
|
|
68
68
|
exports.chunkArrByMaxSize = chunkArrByMaxSize;
|
|
69
69
|
function debouncePromise(caller, delay) {
|
|
@@ -91,12 +91,4 @@ function buildHttpAgents() {
|
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
exports.buildHttpAgents = buildHttpAgents;
|
|
94
|
-
var mergeObjects = function (first, second) {
|
|
95
|
-
for (var _i = 0, _a = Object.entries(second); _i < _a.length; _i++) {
|
|
96
|
-
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
97
|
-
first[key] = value;
|
|
98
|
-
}
|
|
99
|
-
return first;
|
|
100
|
-
};
|
|
101
|
-
exports.mergeObjects = mergeObjects;
|
|
102
94
|
//# sourceMappingURL=utils.js.map
|
package/dist/cjs/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kEAAmC;AAInC,IAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,gBAAgB,CAAU,CAAC;AAI/E,IAAM,eAAe,GAAG,UAC7B,MAAS;IAET,IAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAa,UAAC,GAAG,EAAE,CAAC;QAC9D,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAoC,CA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AAI,CAAC,UAAC,CAAC,IAAK,OAAA,GAAG,CAAC,CAAC,CAAC,EAAN,CAAM,CAAC,CAAC,KAAK,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,GAAG,CAAC,EAAR,CAAQ,CAAC,EAArD,CAAqD,EAC3D,KAAK,CACN,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAfD,0CAeC;AAED,SAAgB,eAAe;IAC7B,IAAM,kBAAkB,GAAG;QACzB,UAAU,EAAE,GAAG;QACf,cAAc,EAAE,EAAE;QAElB,OAAO,EAAE,KAAK;QAEd,iBAAiB,EAAE,KAAK;KACzB,CAAC;IAEF,IAAM,SAAS,GAAG,IAAI,wBAAK,CAAC,kBAAkB,CAAC,CAAC;IAChD,IAAM,UAAU,GAAG,IAAI,wBAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC5D,OAAO;QACL,SAAS,WAAA;QACT,UAAU,YAAA;KACX,CAAC;AACJ,CAAC;AAhBD,0CAgBC"}
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { BaseApi } from './baseApi';
|
|
11
11
|
import { BatchProcessStatus } from '@onereach/types-contacts-api';
|
|
12
12
|
import { debouncePromise } from '../utils';
|
|
13
|
-
import { FAILED_REQUEST_REPEATS
|
|
13
|
+
import { FAILED_REQUEST_REPEATS } from '../constants';
|
|
14
14
|
import { CreateContactsBatchError } from '../apiError';
|
|
15
15
|
export default class BaseWithPoling extends BaseApi {
|
|
16
16
|
constructor(apiCall, batchProcessApi) {
|
|
@@ -18,28 +18,20 @@ export default class BaseWithPoling extends BaseApi {
|
|
|
18
18
|
this.apiCall = apiCall;
|
|
19
19
|
this.batchProcessApi = batchProcessApi;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
this.logger = logger;
|
|
23
|
-
}
|
|
24
|
-
polling(batchId, polingDuration = BULK_POLING_PAUSE_DURATION, repeats = 0) {
|
|
25
|
-
var _a;
|
|
21
|
+
polling(batchId, repeats = 0) {
|
|
26
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
23
|
let batchProcess;
|
|
28
24
|
try {
|
|
29
|
-
batchProcess = yield debouncePromise(() => this.batchProcessApi.getBatchProcess(batchId),
|
|
25
|
+
batchProcess = yield debouncePromise(() => this.batchProcessApi.getBatchProcess(batchId), 1000);
|
|
30
26
|
}
|
|
31
27
|
catch (e) {
|
|
32
28
|
if (repeats < FAILED_REQUEST_REPEATS
|
|
33
29
|
&& 'statusCode' in e
|
|
34
|
-
&& e.statusCode ===
|
|
35
|
-
|
|
36
|
-
return yield debouncePromise(() => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const result = yield this.polling(batchId, polingDuration, repeats + 1);
|
|
38
|
-
return result;
|
|
39
|
-
}), (repeats + 1) * polingDuration);
|
|
30
|
+
&& e.statusCode === 410) {
|
|
31
|
+
return yield debouncePromise(() => this.polling(batchId, repeats + 1), 2000);
|
|
40
32
|
}
|
|
41
33
|
if (repeats < FAILED_REQUEST_REPEATS) {
|
|
42
|
-
return this.polling(batchId,
|
|
34
|
+
return this.polling(batchId, repeats + 1);
|
|
43
35
|
}
|
|
44
36
|
throw new CreateContactsBatchError(e.message, batchId);
|
|
45
37
|
}
|
|
@@ -47,7 +39,7 @@ export default class BaseWithPoling extends BaseApi {
|
|
|
47
39
|
throw new CreateContactsBatchError('Could not complete batch process', batchId, batchProcess.messages);
|
|
48
40
|
}
|
|
49
41
|
return batchProcess.status === BatchProcessStatus.pending
|
|
50
|
-
? this.polling(batchId
|
|
42
|
+
? this.polling(batchId)
|
|
51
43
|
: batchProcess;
|
|
52
44
|
});
|
|
53
45
|
}
|