Skip to content

[Topgear] Fix legacy resource sync issue #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 12 additions & 1 deletion src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -197,5 +207,6 @@ module.exports = {
prepare,
ESFeederServiceClient,
queryDataFromDB,
executeSQLonDB
executeSQLonDB,
forceV4ESFeeder
}
5 changes: 5 additions & 0 deletions src/services/ProcessorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down