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

Commit 555f903

Browse files
Merge pull request #38 from topcoder-platform/develop
Fixes
2 parents 4a31ba9 + 1113587 commit 555f903

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/services/ProcessorService.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function syncChallengePhases (legacyId, v5Phases) {
3636
(!v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Open)) {
3737
const newStatus = v5Equivalent.isOpen
3838
? constants.PhaseStatusTypes.Open
39-
: (new Date().getTime() <= new Date(v5Equivalent.scheduledStartDate).getTime() ? constants.PhaseStatusTypes.Scheduled : constants.PhaseStatusTypes.Closed)
39+
: (new Date().getTime() <= new Date(v5Equivalent.scheduledEndDate).getTime() ? constants.PhaseStatusTypes.Scheduled : constants.PhaseStatusTypes.Closed)
4040
// update phase
4141
logger.debug(`Will update phase ${phase.project_phase_id}/${v5Equivalent.name} to duration ${v5Equivalent.duration * 1000} milli`)
4242
await timelineService.updatePhase(
@@ -467,6 +467,18 @@ async function closeChallenge (challengeId, winnerId) {
467467
return helper.postRequest(`${config.V4_CHALLENGE_API_URL}/${challengeId}/close?winnerId=${winnerId}`, null, m2mToken)
468468
}
469469

470+
/**
471+
* Repost challenge resources on kafka
472+
* @param {String} challengeUuid the V5 challenge UUID
473+
* @param {String} m2mToken the m2m token
474+
*/
475+
async function rePostResourcesOnKafka (challengeUuid, m2mToken) {
476+
const challengeResourcesResponse = await helper.getRequest(`${config.V5_RESOURCES_API_URL}?challengeId=${challengeUuid}&perPage=100`, m2mToken)
477+
for (const resource of (challengeResourcesResponse.body || [])) {
478+
await helper.postBusEvent(config.RESOURCE_CREATE_TOPIC, _.pick(resource, ['id', 'challengeId', 'memberId', 'memberHandle', 'roleId', 'created', 'createdBy', 'updated', 'updatedBy', 'legacyId']))
479+
}
480+
}
481+
470482
/**
471483
* Process create challenge message
472484
* @param {Object} message the kafka message
@@ -515,10 +527,7 @@ async function processCreate (message) {
515527
legacyId: newChallenge.body.result.content.id
516528
}, m2mToken)
517529
// Repost all challenge resource on Kafka so they will get created on legacy by the legacy-challenge-resource-processor
518-
const challengeResourcesResponse = await helper.getRequest(`${config.V5_RESOURCES_API_URL}?challengeId=${challengeUuid}&perPage=100`, m2mToken)
519-
for (const resource of (challengeResourcesResponse.body || [])) {
520-
await helper.postBusEvent(config.RESOURCE_CREATE_TOPIC, _.pick(resource, ['id', 'challengeId', 'memberId', 'memberHandle', 'roleId', 'created', 'createdBy', 'updated', 'updatedBy', 'legacyId']))
521-
}
530+
await rePostResourcesOnKafka(challengeUuid, m2mToken)
522531
await timelineService.enableTimelineNotifications(newChallenge.body.result.content.id, _.get(message, 'payload.createdBy'))
523532
logger.debug('End of processCreate')
524533
return newChallenge.body.result.content.id
@@ -672,6 +681,8 @@ async function processUpdate (message) {
672681
logger.info('Activating challenge...')
673682
await activateChallenge(legacyId)
674683
logger.info('Activated!')
684+
// Repost all challenge resource on Kafka so they will get created on legacy by the legacy-challenge-resource-processor
685+
await rePostResourcesOnKafka(message.payload.id, m2mToken)
675686
}
676687
if (message.payload.status === constants.challengeStatuses.Completed && challenge.currentStatus !== constants.challengeStatuses.Completed) {
677688
if (message.payload.task.isTask) {
@@ -687,8 +698,11 @@ async function processUpdate (message) {
687698
}
688699
}
689700
}
690-
691-
await syncChallengePhases(message.payload.legacyId, message.payload.phases)
701+
if (!_.get(message.payload, 'task.isTask')) {
702+
await syncChallengePhases(message.payload.legacyId, message.payload.phases)
703+
} else {
704+
logger.info('Will skip syncing phases as the challenge is a task...')
705+
}
692706
await updateMemberPayments(message.payload.legacyId, message.payload.prizeSets, _.get(message, 'payload.updatedBy') || _.get(message, 'payload.createdBy'))
693707
await associateChallengeGroups(saveDraftContestDTO.groupsToBeAdded, saveDraftContestDTO.groupsToBeDeleted, legacyId)
694708
await associateChallengeTerms(message.payload.terms, legacyId, _.get(message, 'payload.createdBy'), _.get(message, 'payload.updatedBy') || _.get(message, 'payload.createdBy'))

0 commit comments

Comments
 (0)