File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
src/scripts/crowdin/translations Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments