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

Commit d515ec1

Browse files
author
James Cori
committed
Removing Phase Status Sync
1 parent 021a78f commit d515ec1

File tree

1 file changed

+22
-42
lines changed

1 file changed

+22
-42
lines changed

src/services/ProcessorService.js

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,19 @@ async function recreatePhases (legacyId, v5Phases, createdBy) {
7373
async function syncChallengePhases (legacyId, v5Phases) {
7474
const phaseTypes = await timelineService.getPhaseTypes()
7575
const phasesFromIFx = await timelineService.getChallengePhases(legacyId)
76+
logger.debug(`Phases from IFX: ${JSON.stringify(phasesFromIFx)}`)
7677
for (const phase of phasesFromIFx) {
7778
const phaseName = _.get(_.find(phaseTypes, pt => pt.phase_type_id === phase.phase_type_id), 'name')
7879
const v5Equivalent = _.find(v5Phases, p => p.name === phaseName)
7980
if (v5Equivalent) {
8081
// Compare duration and status
81-
if (v5Equivalent.duration * 1000 !== phase.duration ||
82-
(v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Closed) ||
83-
(!v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Open)) {
84-
const newStatus = v5Equivalent.isOpen
85-
? constants.PhaseStatusTypes.Open
86-
: (new Date().getTime() <= new Date(v5Equivalent.scheduledEndDate).getTime() ? constants.PhaseStatusTypes.Scheduled : constants.PhaseStatusTypes.Closed)
82+
if (v5Equivalent.duration * 1000 !== phase.duration) {
83+
// ||
84+
// (v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Closed) ||
85+
// (!v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Open)) {
86+
// const newStatus = v5Equivalent.isOpen
87+
// ? constants.PhaseStatusTypes.Open
88+
// : (new Date().getTime() <= new Date(v5Equivalent.scheduledEndDate).getTime() ? constants.PhaseStatusTypes.Scheduled : constants.PhaseStatusTypes.Closed)
8789
// update phase
8890
logger.debug(`Will update phase ${phase.project_phase_id}/${v5Equivalent.name} to duration ${v5Equivalent.duration * 1000} milli`)
8991
await timelineService.updatePhase(
@@ -92,7 +94,9 @@ async function syncChallengePhases (legacyId, v5Phases) {
9294
v5Equivalent.scheduledStartDate,
9395
v5Equivalent.scheduledEndDate,
9496
v5Equivalent.duration * 1000,
95-
newStatus)
97+
phase.phase_status_id
98+
)
99+
// newStatus)
96100
}
97101
}
98102
}
@@ -675,29 +679,12 @@ async function processUpdate (message) {
675679
throw new Error(`Could not find challenge ${legacyId}`)
676680
}
677681
} catch (e) {
678-
// postponne kafka event
682+
// postpone kafka event
679683
logger.warn(`Error getting challenge by id, RETRY TURNED OFF ${JSON.stringify(e)}`)
680-
// logger.info('Challenge does not exist yet. Will post the same message back to the bus API')
681-
// logger.error(`Error: ${JSON.stringify(e)}`)
682-
683-
// const retryCountIdentifier = `${config.KAFKA_GROUP_ID.split(' ').join('_')}_retry_count`
684-
// let currentRetryCount = parseInt(_.get(message.payload, retryCountIdentifier, 1), 10)
685-
// if (currentRetryCount <= config.MAX_RETRIES) {
686-
// await new Promise((resolve) => {
687-
// setTimeout(async () => {
688-
// currentRetryCount += 1
689-
// await helper.postBusEvent(config.UPDATE_CHALLENGE_TOPIC, { ...message.payload, [retryCountIdentifier]: currentRetryCount })
690-
// resolve()
691-
// }, config.RETRY_TIMEOUT * currentRetryCount)
692-
// })
693-
// } else {
694-
// logger.error(`Failed to process message after ${config.MAX_RETRIES} retries. Aborting...`)
695-
// }
696-
// return
697684
}
698685

699686
const v4GroupIds = await groupService.getGroupsForChallenge(legacyId)
700-
logger.info(`GroupIDs Found in Informix: ${JSON.stringify(v4GroupIds)}`)
687+
// logger.info(`GroupIDs Found in Informix: ${JSON.stringify(v4GroupIds)}`)
701688

702689
const saveDraftContestDTO = await parsePayload(message.payload, m2mToken, false, v4GroupIds)
703690
logger.debug('Result from parsePayload:')
@@ -717,20 +704,7 @@ async function processUpdate (message) {
717704
logger.warn(`Failed to set ${constants.supportedMetadata[metadataKey].description} to ${metaValue}`)
718705
}
719706
}
720-
// Thomas - get rid of this and add required info directly via IFX
721-
// try {
722-
// if (challenge) {
723-
// await helper.putRequest(`${config.V4_CHALLENGE_API_URL}/${legacyId}`, { param: _.omit(saveDraftContestDTO, ['groupsToBeAdded', 'groupsToBeDeleted']) }, m2mToken)
724-
// }
725-
// } catch (e) {
726-
// logger.warn('Failed to update the challenge via the V4 API')
727-
// logger.error(e)
728-
// }
729-
if (!_.get(message.payload, 'task.isTask')) {
730-
await syncChallengePhases(legacyId, message.payload.phases)
731-
} else {
732-
logger.info('Will skip syncing phases as the challenge is a task...')
733-
}
707+
734708
await updateMemberPayments(legacyId, message.payload.prizeSets, updatedByUserId)
735709
await associateChallengeGroups(saveDraftContestDTO.groupsToBeAdded, saveDraftContestDTO.groupsToBeDeleted, legacyId)
736710
await associateChallengeTerms(message.payload.terms, legacyId, createdByUserId, updatedByUserId)
@@ -740,8 +714,8 @@ async function processUpdate (message) {
740714
// logger.info(`The status has changed from ${challenge.currentStatus} to ${message.payload.status}`)
741715
if (message.payload.status === constants.challengeStatuses.Active && challenge.currentStatus !== constants.challengeStatuses.Active) {
742716
logger.info('Activating challenge...')
743-
await activateChallenge(legacyId)
744-
logger.info('Activated!')
717+
const activated = await activateChallenge(legacyId)
718+
logger.info(`Activated! ${JSON.stringify(activated)}`)
745719
// Repost all challenge resource on Kafka so they will get created on legacy by the legacy-challenge-resource-processor
746720
await rePostResourcesOnKafka(message.payload.id, m2mToken)
747721
}
@@ -758,6 +732,12 @@ async function processUpdate (message) {
758732
logger.info('Challenge type is not a task.. Skip closing challenge...')
759733
}
760734
}
735+
736+
if (!_.get(message.payload, 'task.isTask')) {
737+
await syncChallengePhases(legacyId, challenge.phases)
738+
} else {
739+
logger.info('Will skip syncing phases as the challenge is a task...')
740+
}
761741
}
762742

763743
try {

0 commit comments

Comments
 (0)