Skip to content

Commit 8890980

Browse files
authored
Merge pull request topcoder-archive#137 from topcoder-platform/PLAT-2035
2 parents ef7bccd + 698b90e commit 8890980

File tree

7 files changed

+48
-9
lines changed

7 files changed

+48
-9
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ workflows:
7272
branches:
7373
only:
7474
- develop
75+
- PLAT-2035
7576

7677
# Production builds are exectuted only on tagged commits to the
7778
# master branch.

compose-dev.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
app:
3+
entrypoint:
4+
- sleep
5+
- infinity
6+
image: node:10.15.1
7+
platform: linux/amd64
8+
init: true
9+
volumes:
10+
- type: bind
11+
source: /var/run/docker.sock
12+
target: /var/run/docker.sock
13+

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,8 @@
5858
"test/unit/test.js",
5959
"test/e2e/test.js"
6060
]
61+
},
62+
"volta": {
63+
"node": "12.22.12"
6164
}
6265
}

src/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require('./bootstrap')
66
const _ = require('lodash')
77
const config = require('config')
88
const Kafka = require('no-kafka')
9-
const healthcheck = require('@topcoder-platform/topcoder-healthcheck-dropin')
9+
// const healthcheck = require('@topcoder-platform/topcoder-healthcheck-dropin')
1010
const logger = require('./common/logger')
1111
const helper = require('./common/helper')
1212
const ProcessorService = require('./services/ProcessorService')
@@ -110,7 +110,7 @@ consumer
110110
// consume configured topics
111111
.then(() => {
112112
logger.info('Initialized.......')
113-
healthcheck.init([check])
113+
// healthcheck.init([check])
114114
logger.info('Adding topics successfully.......')
115115
logger.info(topics)
116116
logger.info('Kick Start.......')

src/services/ProcessorService.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async function recreatePhases (legacyId, v5Phases, createdBy) {
9999
* @param {Boolean} isSelfService is the challenge self-service
100100
* @param {String} createdBy the created by
101101
*/
102-
async function syncChallengePhases (legacyId, v5Phases, createdBy, isSelfService, numOfReviewers) {
102+
async function syncChallengePhases (legacyId, v5Phases, createdBy, isSelfService, numOfReviewers, isBeingActivated) {
103103
const phaseTypes = await timelineService.getPhaseTypes()
104104
const phasesFromIFx = await timelineService.getChallengePhases(legacyId)
105105
logger.debug(`Phases from v5: ${JSON.stringify(v5Phases)}`)
@@ -131,14 +131,26 @@ async function syncChallengePhases (legacyId, v5Phases, createdBy, isSelfService
131131
if (v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Closed) {
132132
newStatus = constants.PhaseStatusTypes.Scheduled
133133
}
134+
135+
if (isBeingActivated && ['Registration', 'Submission'].indexOf(v5Equivalent.name) != -1) {
136+
const scheduledStartDate = v5Equivalent.scheduledStartDate;
137+
const now = new Date().getTime();
138+
if (scheduledStartDate != null && new Date(scheduledStartDate).getTime() < now) {
139+
newStatus = constants.PhaseStatusTypes.Open;
140+
}
141+
142+
logger.debug(`Challenge phase ${v5Equivalent.name} status is being set to: ${newStatus} on challenge activation.`)
143+
}
144+
134145
await timelineService.updatePhase(
135146
phase.project_phase_id,
136147
legacyId,
137148
phase.fixed_start_time ? v5Equivalent.scheduledStartDate : null,
138149
v5Equivalent.scheduledStartDate,
139150
v5Equivalent.scheduledEndDate,
140151
v5Equivalent.duration * 1000,
141-
newStatus
152+
newStatus,
153+
isBeingActivated && newStatus == constants.PhaseStatusTypes.Open ? new Date() : null
142154
)
143155
} else {
144156
logger.info(`number of ${phaseName} does not match`)
@@ -759,11 +771,14 @@ async function processMessage (message) {
759771
}
760772
}
761773

774+
let isBeingActivated = false;
775+
762776
if (message.payload.status && challenge) {
763777
// Whether we need to sync v4 ES again
764778
let needSyncV4ES = false
765779
// logger.info(`The status has changed from ${challenge.currentStatus} to ${message.payload.status}`)
766780
if (message.payload.status === constants.challengeStatuses.Active && challenge.currentStatus !== constants.challengeStatuses.Active) {
781+
isBeingActivated = true;
767782
logger.info('Activating challenge...')
768783
const activated = await activateChallenge(legacyId)
769784
logger.info(`Activated! ${JSON.stringify(activated)}`)
@@ -790,7 +805,7 @@ async function processMessage (message) {
790805

791806
if (!_.get(message.payload, 'task.isTask')) {
792807
const numOfReviewers = 2
793-
await syncChallengePhases(legacyId, message.payload.phases, createdByUserId, _.get(message, 'payload.legacy.selfService'), numOfReviewers)
808+
await syncChallengePhases(legacyId, message.payload.phases, createdByUserId, _.get(message, 'payload.legacy.selfService'), numOfReviewers, isBeingActivated)
794809
needSyncV4ES = true
795810
} else {
796811
logger.info('Will skip syncing phases as the challenge is a task...')

src/services/timelineService.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const QUERY_GET_CHALLENGE_PHASES = 'SELECT project_phase_id, fixed_start_time, s
1919
const QUERY_DROP_CHALLENGE_PHASE = 'DELETE FROM project_phase WHERE project_id = ? AND project_phase_id = ?'
2020
const QUERY_INSERT_CHALLENGE_PHASE = 'INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, CURRENT, ?, CURRENT)'
2121
const QUERY_UPDATE_CHALLENGE_PHASE = 'UPDATE project_phase SET fixed_start_time = ?, scheduled_start_time = ?, scheduled_end_time = ?, duration = ?, phase_status_id = ? WHERE project_phase_id = %d and project_id = %d'
22+
const QUERY_UPDATE_CHALLENGE_PHASE_WITH_START_TIME = 'UPDATE project_phase SET fixed_start_time = ?, scheduled_start_time = ?, scheduled_end_time = ?, duration = ?, phase_status_id = ?, actual_start_time = ? WHERE project_phase_id = %d and project_id = %d'
2223

2324
const QUERY_DROP_CHALLENGE_PHASE_CRITERIA = 'DELETE FROM phase_criteria WHERE project_phase_id = ?'
2425

@@ -237,13 +238,19 @@ async function createPhase (challengeLegacyId, phaseTypeId, statusTypeId, schedu
237238
* @param {Date} duration the duration
238239
* @param {Number} statusTypeId the status type ID
239240
*/
240-
async function updatePhase (phaseId, challengeLegacyId, fixedStartTime, startTime, endTime, duration, statusTypeId) {
241+
async function updatePhase (phaseId, challengeLegacyId, fixedStartTime, startTime, endTime, duration, statusTypeId, actualStartTime) {
241242
const connection = await helper.getInformixConnection()
242243
let result = null
243244
try {
244245
// await connection.beginTransactionAsync()
245-
const query = await prepare(connection, util.format(QUERY_UPDATE_CHALLENGE_PHASE, phaseId, challengeLegacyId))
246-
result = await query.executeAsync([formatDate(fixedStartTime), formatDate(startTime), formatDate(endTime), duration, statusTypeId])
246+
const query = actualStartTime == null ?
247+
await prepare(connection, util.format(QUERY_UPDATE_CHALLENGE_PHASE, phaseId, challengeLegacyId)) :
248+
await prepare(connection, util.format(QUERY_UPDATE_CHALLENGE_PHASE_WITH_START_TIME, phaseId, challengeLegacyId))
249+
250+
result = actualStartTime == null ?
251+
await query.executeAsync([formatDate(fixedStartTime), formatDate(startTime), formatDate(endTime), duration, statusTypeId]) :
252+
await query.executeAsync([formatDate(fixedStartTime), formatDate(startTime), formatDate(endTime), duration, statusTypeId, formatDate(actualStartTime)])
253+
247254
// await connection.commitTransactionAsync()
248255
} catch (e) {
249256
logger.error(`Error in 'updatePhase' ${e}, rolling back transaction`)

0 commit comments

Comments
 (0)