diff --git a/config/default.js b/config/default.js index 1151353..4c4a8cf 100755 --- a/config/default.js +++ b/config/default.js @@ -40,6 +40,9 @@ module.exports = { CHALLENGE_API_V5_URL: process.env.CHALLENGE_API_V5_URL || 'http://localhost:3001/v5/challenges', RESOURCE_ROLE_API_URL: process.env.RESOURCE_ROLE_API_URL || 'http://localhost:3001/v5/resource-roles', + V4_ES_FEEDER_API_URL: process.env.V4_ES_FEEDER_API_URL || 'https://api.topcoder-dev.com/v4/esfeeder/challenges', + INDEX_CHALLENGE_TIMEOUT: process.env.INDEX_CHALLENGE_TIMEOUT || 2, + AUTH0_URL: process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token', // Auth0 credentials for M2M token AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://m2m.topcoder-dev.com/', AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID || 'e6oZAxnoFvjdRtjJs1Jt3tquLnNSTs0e', diff --git a/src/common/helper.js b/src/common/helper.js index 8d4b69a..d4fe026 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -187,6 +187,16 @@ async function executeSQLonDB (sql, params) { } } +async function forceV4ESFeeder (legacyId) { + const token = await getM2Mtoken() + const body = { + param: { + challengeIds: [legacyId] + } + } + await request.put(`${config.V4_ES_FEEDER_API_URL}`).send(body).set({ Authorization: `Bearer ${token}` }) +} + module.exports = { getInformixConnection, getM2Mtoken, @@ -197,5 +207,6 @@ module.exports = { prepare, ESFeederServiceClient, queryDataFromDB, - executeSQLonDB + executeSQLonDB, + forceV4ESFeeder } diff --git a/src/services/ProcessorService.js b/src/services/ProcessorService.js index d6fa186..91e1ea0 100755 --- a/src/services/ProcessorService.js +++ b/src/services/ProcessorService.js @@ -92,6 +92,11 @@ async function _updateChallengeResource (message, isDelete) { } if (resourceRole.id === config.SUBMITTER_ROLE_ID && !isTask) { + // force sync v4 elasticsearch service + logger.debug(`Start v4 challenge reindexing to the elasticsearch service`) + await helper.forceV4ESFeeder(_.get(v5Challenge, 'legacyId')); + await new Promise(resolve => setTimeout(resolve, config.INDEX_CHALLENGE_TIMEOUT * 1000)); + logger.debug(`End v4 challenge reindexing to the elasticsearch service`) if (isDelete) { logger.debug(`v4 Unregistering Submitter ${config.CHALLENGE_API_V4_URL}/${_.get(v5Challenge, 'legacyId')}/unregister?userId=${userId} - ${JSON.stringify(body)}`) await helper.postRequest(`${config.CHALLENGE_API_V4_URL}/${_.get(v5Challenge, 'legacyId')}/unregister?userId=${userId}`, {}, m2mToken)