Skip to content

Commit

Permalink
Asyncify www pull & handle failed pulls
Browse files Browse the repository at this point in the history
  • Loading branch information
seotts authored and Cori Hudson committed Sep 20, 2022
1 parent 724ab3b commit 842704f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
9 changes: 8 additions & 1 deletion lib/transifex.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ const getDownloadFileLocation = async function (downloadEventId, isSourceLocale)
// eslint-disable-next-line no-constant-condition
while (true) {
try {
await statusEndpoint.get(downloadEventId);
const downloadStatus = await statusEndpoint.get(downloadEventId);

if (downloadStatus.attributes.status === 'failed') {
if (downloadStatus.attributes.errors.length() > 0) {
throw new Error(downloadStatus.attributes.errors);
}
throw new Error('Error downloading file');
}

/** If there is no error from getting the status, the download is still pending.
Wait before trying again. **/
Expand Down
35 changes: 16 additions & 19 deletions scripts/tx-pull-www.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,25 @@ const CONCURRENCY_LIMIT = 4;

const lang = args.length === 2 ? args[1] : '';

const getLocaleData = (item, callback) => {
const getLocaleData = async function (item) {
const locale = item.locale;
const resource = item.resource;
let txLocale = localeMap[locale] || locale;
txPull(PROJECT, resource, txLocale, function (err, translations) {
if (err) {
callback(err);
} else {
const txOutdir = `${OUTPUT_DIR}/${PROJECT}.${resource}`;
mkdirp.sync(txOutdir);
const fileName = `${txOutdir}/${locale}.json`;
fs.writeFileSync(
fileName,
JSON.stringify(translations, null, 4)
);
callback(null, {
resource: resource,
locale: locale,
file: fileName
});
}
});

const translations = await txPull(PROJECT, resource, txLocale);

const txOutdir = `${OUTPUT_DIR}/${PROJECT}.${resource}`;
mkdirp.sync(txOutdir);
const fileName = `${txOutdir}/${locale}.json`;
fs.writeFileSync(
fileName,
JSON.stringify(translations, null, 4)
);
return {
resource: resource,
locale: locale,
file: fileName
};
};

const expandResourceFiles = (resources) => {
Expand Down

0 comments on commit 842704f

Please sign in to comment.