Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Commit

Permalink
resync v4 es feeder
Browse files Browse the repository at this point in the history
  • Loading branch information
LieutenantRoger committed May 2, 2022
1 parent 62ea2d8 commit d68ed47
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/services/ProcessorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,8 @@ async function processMessage (message) {
}

if (message.payload.status && challenge) {
// Whether we need to sync v4 ES again
let needSyncV4ES = false
// logger.info(`The status has changed from ${challenge.currentStatus} to ${message.payload.status}`)
if (message.payload.status === constants.challengeStatuses.Active && challenge.currentStatus !== constants.challengeStatuses.Active) {
logger.info('Activating challenge...')
Expand All @@ -708,6 +710,7 @@ async function processMessage (message) {
await metadataService.createOrUpdateMetadata(legacyId, 9, 'On', createdByUserId) // autopilot
// Repost all challenge resource on Kafka so they will get created on legacy by the legacy-challenge-resource-processor
await rePostResourcesOnKafka(challengeUuid, m2mToken)
needSyncV4ES = true
}
if (message.payload.status === constants.challengeStatuses.Completed && challenge.currentStatus !== constants.challengeStatuses.Completed) {
if (message.payload.task.isTask) {
Expand All @@ -718,6 +721,7 @@ async function processMessage (message) {
const winnerId = _.find(message.payload.winners, winner => winner.placement === 1).userId
logger.info(`Will close the challenge with ID ${legacyId}. Winner ${winnerId}!`)
await closeChallenge(legacyId, winnerId)
needSyncV4ES = true
} else {
logger.info('Challenge type is not a task.. Skip closing challenge...')
}
Expand All @@ -726,9 +730,18 @@ async function processMessage (message) {
if (!_.get(message.payload, 'task.isTask')) {
const numOfReviewers = 2
await syncChallengePhases(legacyId, message.payload.phases, createdByUserId, _.get(message, 'payload.legacy.selfService'), numOfReviewers)
needSyncV4ES = true
} else {
logger.info('Will skip syncing phases as the challenge is a task...')
}
if (needSyncV4ES) {
try {
logger.info(`Resync V4 ES for the legacy challenge ${legacyId}`)
await helper.forceV4ESFeeder(legacyId)
} catch (e) {
logger.warn(`Resync V4 - Failed to call V4 ES Feeder ${JSON.stringify(e)}`)
}
}
}
}

Expand Down

0 comments on commit d68ed47

Please sign in to comment.