rads-db 3.0.76 → 3.0.77
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/drivers/azureCosmos.cjs +22 -5
- package/drivers/azureCosmos.mjs +25 -9
- package/package.json +1 -1
package/drivers/azureCosmos.cjs
CHANGED
|
@@ -124,14 +124,31 @@ var _default = options => (schema, entity) => {
|
|
|
124
124
|
...item
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
|
-
for (const chunk of _lodash.default.chunk(itemsToPut,
|
|
128
|
-
|
|
127
|
+
for (const chunk of _lodash.default.chunk(itemsToPut, 100)) {
|
|
128
|
+
let chunkToSend = chunk.map(x => ({
|
|
129
129
|
operationType: "Upsert",
|
|
130
130
|
resourceBody: x
|
|
131
|
-
}))
|
|
131
|
+
}));
|
|
132
|
+
const responses = [];
|
|
133
|
+
for (let i = 0; i < 20; i++) {
|
|
134
|
+
const response = await client.items.bulk(chunkToSend);
|
|
135
|
+
const newChunkToSend = [];
|
|
136
|
+
for (let i2 = 0; i2 < chunkToSend.length; i2++) {
|
|
137
|
+
if (response[i2].statusCode !== 429) {
|
|
138
|
+
responses.push(response[i2]);
|
|
139
|
+
} else {
|
|
140
|
+
newChunkToSend.push(chunkToSend[i2]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
chunkToSend = newChunkToSend;
|
|
144
|
+
if (chunkToSend.length === 0) break;
|
|
145
|
+
const delay = 50 + i * 100;
|
|
146
|
+
console.warn(`Db overloaded. Retrying after ${delay}ms...`);
|
|
147
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
148
|
+
}
|
|
132
149
|
ctx?.log?.({
|
|
133
|
-
charge: _lodash.default.sumBy(
|
|
134
|
-
request: `put#${
|
|
150
|
+
charge: _lodash.default.sumBy(responses, r => r.requestCharge),
|
|
151
|
+
request: `put#${chunk[0]._partition}[${chunk.length}]`
|
|
135
152
|
});
|
|
136
153
|
}
|
|
137
154
|
}
|
package/drivers/azureCosmos.mjs
CHANGED
|
@@ -80,16 +80,32 @@ export default (options) => (schema, entity) => {
|
|
|
80
80
|
throw new Error(`You must provide an id`);
|
|
81
81
|
itemsToPut.push({ _partition: entity, id, ...item });
|
|
82
82
|
}
|
|
83
|
-
for (const chunk of _.chunk(itemsToPut,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
)
|
|
83
|
+
for (const chunk of _.chunk(itemsToPut, 100)) {
|
|
84
|
+
let chunkToSend = chunk.map((x) => ({
|
|
85
|
+
operationType: "Upsert",
|
|
86
|
+
resourceBody: x
|
|
87
|
+
}));
|
|
88
|
+
const responses = [];
|
|
89
|
+
for (let i = 0; i < 20; i++) {
|
|
90
|
+
const response = await client.items.bulk(chunkToSend);
|
|
91
|
+
const newChunkToSend = [];
|
|
92
|
+
for (let i2 = 0; i2 < chunkToSend.length; i2++) {
|
|
93
|
+
if (response[i2].statusCode !== 429) {
|
|
94
|
+
responses.push(response[i2]);
|
|
95
|
+
} else {
|
|
96
|
+
newChunkToSend.push(chunkToSend[i2]);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
chunkToSend = newChunkToSend;
|
|
100
|
+
if (chunkToSend.length === 0)
|
|
101
|
+
break;
|
|
102
|
+
const delay = 50 + i * 100;
|
|
103
|
+
console.warn(`Db overloaded. Retrying after ${delay}ms...`);
|
|
104
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
105
|
+
}
|
|
90
106
|
ctx?.log?.({
|
|
91
|
-
charge: _.sumBy(
|
|
92
|
-
request: `put#${
|
|
107
|
+
charge: _.sumBy(responses, (r) => r.requestCharge),
|
|
108
|
+
request: `put#${chunk[0]._partition}[${chunk.length}]`
|
|
93
109
|
});
|
|
94
110
|
}
|
|
95
111
|
}
|