Skip to content

Commit 0227f9b

Browse files
Fred GruberFred Gruber
authored andcommitted
This commit fixes error when updating multiple confluence attachments
Essentially, it uploads attachments one at a time instead of in parallel. Currently using a 0.8 second delay.
1 parent 10af0a2 commit 0227f9b

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/publish/confluence/confluence.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,26 @@ async function publish(
435435
LogPrefix.ATTACHMENT,
436436
);
437437

438-
const uploadAttachmentsResult = await Promise.all(
439-
uploadAttachments(
440-
publishFiles.baseDir,
441-
attachmentsToUpload,
442-
toUpdate.id,
443-
fileName,
444-
existingAttachments,
445-
),
446-
);
438+
const uploadAttachmentsResult: unknown[] = [];
439+
440+
for (const att of attachmentsToUpload) {
441+
// Start exactly ONE upload by calling the helper with a single attachment
442+
const tasks = uploadAttachments(
443+
publishFiles.baseDir,
444+
[att], // <-- one at a time
445+
toUpdate.id,
446+
fileName,
447+
existingAttachments,
448+
) as Promise<unknown>[]; // uploadAttachments returns an array of Promises
449+
450+
const res = await tasks[0];
451+
uploadAttachmentsResult.push(res);
452+
453+
// short backoff (milliseconds)
454+
const t0 = performance.now();
455+
await new Promise<void>(r => setTimeout(r, 800)); // 0.8s
456+
trace("[ATTACHMENT] sleptMs", { ms: Math.round(performance.now() - t0) }, LogPrefix.ATTACHMENT);
457+
}
447458
trace(
448459
"uploadAttachmentsResult",
449460
uploadAttachmentsResult,

0 commit comments

Comments
 (0)