Skip to content

Commit 1bc8723

Browse files
Merge pull request #38 from topcoder-platform/fix-legacy-sync
[Topgear] Fix legacy resource sync issue
2 parents 98d0711 + 1817bf5 commit 1bc8723

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

config/default.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ module.exports = {
4040
CHALLENGE_API_V5_URL: process.env.CHALLENGE_API_V5_URL || 'http://localhost:3001/v5/challenges',
4141
RESOURCE_ROLE_API_URL: process.env.RESOURCE_ROLE_API_URL || 'http://localhost:3001/v5/resource-roles',
4242

43+
V4_ES_FEEDER_API_URL: process.env.V4_ES_FEEDER_API_URL || 'https://api.topcoder-dev.com/v4/esfeeder/challenges',
44+
INDEX_CHALLENGE_TIMEOUT: process.env.INDEX_CHALLENGE_TIMEOUT || 2,
45+
4346
AUTH0_URL: process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token', // Auth0 credentials for M2M token
4447
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://m2m.topcoder-dev.com/',
4548
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID || 'e6oZAxnoFvjdRtjJs1Jt3tquLnNSTs0e',

src/common/helper.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ async function executeSQLonDB (sql, params) {
187187
}
188188
}
189189

190+
async function forceV4ESFeeder (legacyId) {
191+
const token = await getM2Mtoken()
192+
const body = {
193+
param: {
194+
challengeIds: [legacyId]
195+
}
196+
}
197+
await request.put(`${config.V4_ES_FEEDER_API_URL}`).send(body).set({ Authorization: `Bearer ${token}` })
198+
}
199+
190200
module.exports = {
191201
getInformixConnection,
192202
getM2Mtoken,
@@ -197,5 +207,6 @@ module.exports = {
197207
prepare,
198208
ESFeederServiceClient,
199209
queryDataFromDB,
200-
executeSQLonDB
210+
executeSQLonDB,
211+
forceV4ESFeeder
201212
}

src/services/ProcessorService.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ async function _updateChallengeResource (message, isDelete) {
9292
}
9393

9494
if (resourceRole.id === config.SUBMITTER_ROLE_ID && !isTask) {
95+
// force sync v4 elasticsearch service
96+
logger.debug(`Start v4 challenge reindexing to the elasticsearch service`)
97+
await helper.forceV4ESFeeder(_.get(v5Challenge, 'legacyId'));
98+
await new Promise(resolve => setTimeout(resolve, config.INDEX_CHALLENGE_TIMEOUT * 1000));
99+
logger.debug(`End v4 challenge reindexing to the elasticsearch service`)
95100
if (isDelete) {
96101
logger.debug(`v4 Unregistering Submitter ${config.CHALLENGE_API_V4_URL}/${_.get(v5Challenge, 'legacyId')}/unregister?userId=${userId} - ${JSON.stringify(body)}`)
97102
await helper.postRequest(`${config.CHALLENGE_API_V4_URL}/${_.get(v5Challenge, 'legacyId')}/unregister?userId=${userId}`, {}, m2mToken)

0 commit comments

Comments
 (0)