Skip to content

Commit 8d92b46

Browse files
committed
fix(ci): retry network resets in dataset sync and use --no-wait on blueprints deploy
1 parent 2c84261 commit 8d92b46

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

‎.github/workflows/deploy.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
echo "Resolved Organization ID: $ORG_ID"
7474
mkdir -p .sanity
7575
echo "{\"organizationId\":\"$ORG_ID\"}" > .sanity/blueprint.config.json
76-
pnpm exec sanity blueprints deploy --organization-id "$ORG_ID" --stack ${{ vars.SANITY_STUDIO_DATASET }} --non-interactive
76+
pnpm exec sanity blueprints deploy --organization-id "$ORG_ID" --stack ${{ vars.SANITY_STUDIO_DATASET }} --no-wait
7777
env:
7878
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}
7979
SANITY_API_WRITE_TOKEN: ${{ secrets.SANITY_API_WRITE_TOKEN }}
@@ -147,7 +147,7 @@ jobs:
147147
echo "Resolved Organization ID: $ORG_ID"
148148
mkdir -p .sanity
149149
echo "{\"organizationId\":\"$ORG_ID\"}" > .sanity/blueprint.config.json
150-
pnpm exec sanity blueprints deploy --organization-id "$ORG_ID" --stack ${{ vars.SANITY_STUDIO_DATASET }} --non-interactive
150+
pnpm exec sanity blueprints deploy --organization-id "$ORG_ID" --stack ${{ vars.SANITY_STUDIO_DATASET }} --no-wait
151151
env:
152152
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_AUTH_TOKEN }}
153153
SANITY_API_WRITE_TOKEN: ${{ secrets.SANITY_API_WRITE_TOKEN }}

‎.github/workflows/nightly-dataset-sync.yml‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,24 @@ jobs:
199199
200200
let activeToken = tokens[0];
201201
async function mutateBatch(mutations, dataset = "dev") {
202-
for (let attempt = 0; attempt < 5; attempt++) {
202+
for (let attempt = 0; attempt < 6; attempt++) {
203203
const token = activeToken || tokens[attempt % tokens.length];
204-
const res = await fetch(`https://${projectId}.api.sanity.io/v2021-06-07/data/mutate/${dataset}?visibility=sync&autoGenerateArrayKeys=true`, {
205-
method: "POST",
206-
headers: {
207-
Authorization: `Bearer ${token}`,
208-
"Content-Type": "application/json",
209-
},
210-
body: JSON.stringify({ mutations }),
211-
});
204+
let res;
205+
try {
206+
res = await fetch(`https://${projectId}.api.sanity.io/v2021-06-07/data/mutate/${dataset}?visibility=sync&autoGenerateArrayKeys=true`, {
207+
method: "POST",
208+
headers: {
209+
Authorization: `Bearer ${token}`,
210+
"Content-Type": "application/json",
211+
},
212+
body: JSON.stringify({ mutations }),
213+
});
214+
} catch (netErr) {
215+
const delay = 1000 * Math.pow(2, attempt);
216+
console.warn(`Network error (${netErr.message}), retrying in ${delay}ms...`);
217+
await new Promise((r) => setTimeout(r, delay));
218+
continue;
219+
}
212220
if (res.ok) {
213221
activeToken = token;
214222
return;
@@ -226,15 +234,15 @@ jobs:
226234
}
227235
throw new Error(`Mutate batch (${dataset}) failed: HTTP ${res.status}: ${errText}`);
228236
}
229-
throw new Error(`Mutate batch (${dataset}) failed after 5 retries.`);
237+
throw new Error(`Mutate batch (${dataset}) failed after 6 retries.`);
230238
}
231239
232240
async function sendChunked(items, label, op = "createOrReplace") {
233241
let batch = [];
234242
let batchBytes = 0;
235243
let sent = 0;
236-
const MAX_ITEMS = 200;
237-
const MAX_BYTES = 2500000;
244+
const MAX_ITEMS = 100;
245+
const MAX_BYTES = 1500000;
238246
239247
for (const item of items) {
240248
const mutation = op === "raw" ? item : { [op]: item };

0 commit comments

Comments
 (0)