Skip to content

Commit e99cf23

Browse files
committed
feat: create awaitLatestBuild script
1 parent 351a26d commit e99cf23

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import crowdin from "../api-client/crowdinClient"
2+
3+
async function awaitLatestBuild() {
4+
const FINISHED = "finished"
5+
const TIMEOUT = 2 * 60 * 60 * 1000 // 2 hours in milliseconds
6+
7+
const projectId = Number(process.env.CROWDIN_PROJECT_ID) || 363359
8+
9+
const initialResponse = await crowdin.translationsApi.listProjectBuilds(
10+
projectId
11+
)
12+
13+
let data = initialResponse.data
14+
let isFinished = data[0].data.status === FINISHED
15+
16+
const timeoutTime = Date.now() + TIMEOUT
17+
while (!isFinished && Date.now() < timeoutTime) {
18+
const repeatCheck = await crowdin.translationsApi.listProjectBuilds(
19+
projectId
20+
)
21+
data = repeatCheck.data
22+
isFinished = data[0].data.status === FINISHED
23+
}
24+
const latestBuildData = data[0].data
25+
if (latestBuildData.status !== FINISHED)
26+
throw new Error(
27+
`Timeout: Build did not finish in ${TIMEOUT / 1000 / 60} minutes`
28+
)
29+
}
30+
31+
awaitLatestBuild()
32+
33+
export default awaitLatestBuild

0 commit comments

Comments
 (0)