Skip to content

Commit

Permalink
nex attempt to fix crowdin dl issues
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed May 6, 2021
1 parent 83ce660 commit 13b30b0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
41 changes: 41 additions & 0 deletions website/delayCrowdin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/*
We delay a bit the i18n staging deployment
Because sometimes, prod + i18n-staging call this script at the exact same time
And then both try to dl the translations at the same time, and then we have a 409 error
This delay makes sure prod starts to dl the translations in priority
Used in conjunction with waitForCrowdin.js (which is not enough)
*/

async function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

async function run() {
if (
process.env.NETLIFY === 'true' &&
process.env.SITE_NAME === 'docusaurus-i18n-staging'
) {
console.log(
'[Crowdin] Delaying the docusaurus-i18n-staging deployment to avoid 409 errors',
);
await delay(30000);
}
}

run().then(
() => {
process.exit(0);
},
(e) => {
console.error(e.message);
console.error(e.stack);
process.exit(1);
},
);
3 changes: 2 additions & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"build:bootstrap": "cross-env DOCUSAURUS_PRESET=bootstrap yarn build",
"start:blogOnly": "cross-env yarn start --config=docusaurus.config-blog-only.js",
"build:blogOnly": "cross-env yarn build --config=docusaurus.config-blog-only.js",
"netlify:build:production": "yarn docusaurus write-translations && yarn netlify:crowdin:uploadSources && yarn netlify:crowdin:downloadTranslations && yarn build",
"netlify:build:production": "yarn docusaurus write-translations && yarn netlify:crowdin:delay && yarn netlify:crowdin:uploadSources && yarn netlify:crowdin:downloadTranslations && yarn build",
"netlify:build:deployPreview": "yarn docusaurus write-translations --locale fr --messagePrefix '(fr) ' && yarn build",
"netlify:crowdin:delay": "node delayCrowdin.js",
"netlify:crowdin:wait": "node waitForCrowdin.js",
"netlify:crowdin:downloadTranslations": "yarn netlify:crowdin:wait && yarn --cwd .. crowdin:download:v2",
"netlify:crowdin:downloadTranslationsFailSafe": "yarn netlify:crowdin:wait && (yarn --cwd .. crowdin:download:v2 || echo 'Crowdin translation download failure (only internal PRs have access to the Crowdin env token)')",
Expand Down
25 changes: 8 additions & 17 deletions website/waitForCrowdin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

const {Translations} = require('@crowdin/crowdin-api-client');

/*
Expand Down Expand Up @@ -27,26 +34,10 @@ async function delay(ms) {

async function hasBuildInProgress() {
const projectBuilds = await translations.listProjectBuilds(projectId);
return projectBuilds.data.some(
(build) => build.data.status === 'in-progress',
);
return projectBuilds.data.some((build) => build.data.status === 'inProgress');
}

async function run() {
// We delay a bit the i18n staging deployment
// Because sometimes, prod + i18n-staging call this script at the exact same time
// And then both try to dl the translations at the same time, and then we have a 409 error
// This delay makes sure prod starts to dl the translations in priority
if (
process.env.NETLIFY === 'true' &&
process.env.SITE_NAME === 'docusaurus-i18n-staging'
) {
console.log(
'[Crowdin] Delaying the docusaurus-i18n-staging deployment to avoid 409 errors',
);
await delay(30000);
}

const timeBefore = Date.now();
while (true) {
if (Date.now() - timeBefore > timeout) {
Expand Down

0 comments on commit 13b30b0

Please sign in to comment.