Skip to content

Commit

Permalink
Merge pull request #5071 from newrelic/4816_send_queued_requests
Browse files Browse the repository at this point in the history
Updates to send translation script for using project_id
  • Loading branch information
zstix committed Dec 1, 2021
2 parents 3c786a3 + 7d3de13 commit 9fb8254
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions scripts/actions/send-and-update-translation-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ const PROJECT_ID = process.env.TRANSLATION_VENDOR_PROJECT;
*/
const getReadyToGoTranslationsForEachLocale = async () => {
const [pendingTranslations, inProgressTranslations] = await Promise.all([
Database.getTranslations({ status: 'PENDING' }),
Database.getTranslations({ status: 'IN_PROGRESS' }),
Database.getTranslations({ status: 'PENDING', project_id: PROJECT_ID }),
Database.getTranslations({ status: 'IN_PROGRESS', project_id: PROJECT_ID }),
]);

/*
* We only want to send a translation if:
* 1. It's in a pending state.
* 2. There isn't a matching record whose status === 'IN_PROGRESS'. A record matches if there exists another record with the same slug and locale.
*
* This is to avoid sending multiple translation requests for {hello_world.txt, ja-JP} as an example, and allows us have to an in progress translation, and one ready to go that is queued up in the database.
* This is to avoid sending multiple translation requests for {hello_world.txt, ja-JP} as an example, and allows us to have an in progress translation, and one ready to go that is queued up in the database.
*
* 3. The file (slug) that is associated with the translation record still exists.
*/
Expand Down Expand Up @@ -100,6 +100,7 @@ const createJobs = (accessToken) => async (locales) => {
job_uid: jobResponse.translationJobUid,
status: 'PENDING',
locale: jobResponse.targetLocaleIds[0],
project_id: PROJECT_ID,
});
})
);
Expand Down
5 changes: 3 additions & 2 deletions scripts/actions/translation_workflow/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ const Models = require('./models');
* @param {string} job.job_uid - identifier of job from translation vendor
* @param {string} job.status - string value of status enum
* @param {string} job.locale - locale of job
* @param {string} job.project_id -- project id job is associated with (from translation vendor)
* @returns newly created job
*/
const addJob = async ({ job_uid, status, locale }) => {
const job = await Models.Job.create({ job_uid, status, locale });
const addJob = async ({ job_uid, status, locale, project_id }) => {
const job = await Models.Job.create({ job_uid, status, locale, project_id });
return job;
};

Expand Down

0 comments on commit 9fb8254

Please sign in to comment.