Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 5ddf7a9

Browse files
fix: sequential publish, refresh deck before doing github
1 parent 3072c2f commit 5ddf7a9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

cloud/functions/src/watch/publish/publish.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function publishJob(snap: DocumentSnapshot): Promise<void> {
6565
// Therefore, to avoid such problem, we add a bit of delay in the process but only for the first publish
6666
setTimeout(
6767
async () => {
68-
await publishToGitHub(deck.id, deck.data);
68+
await delayPublishToGitHub(deck.id);
6969
resolve();
7070
},
7171
newPublish ? 5000 : 0
@@ -82,3 +82,18 @@ function publishJob(snap: DocumentSnapshot): Promise<void> {
8282
}
8383
});
8484
}
85+
86+
async function delayPublishToGitHub(deckId: string) {
87+
// It has been changed by the publish to the API
88+
const refreshDeck: Deck = await findDeck(deckId);
89+
90+
if (!refreshDeck || !refreshDeck.data) {
91+
throw new Error('Updated published deck cannot be found');
92+
}
93+
94+
try {
95+
await publishToGitHub(refreshDeck.id, refreshDeck.data);
96+
} catch (err) {
97+
throw err;
98+
}
99+
}

0 commit comments

Comments
 (0)