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

Commit b9b4a06

Browse files
committedFeb 3, 2022
set autopilot to on
1 parent 78cdaf1 commit b9b4a06

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
 

‎src/services/ProcessorService.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ async function createChallenge (saveDraftContestDTO, challengeUuid, createdByUse
604604
// Repost all challenge resource on Kafka so they will get created on legacy by the legacy-challenge-resource-processor
605605
await rePostResourcesOnKafka(challengeUuid, m2mToken)
606606
await timelineService.enableTimelineNotifications(legacyId, createdByUserId)
607+
await metadataService.createOrUpdateMetadata(legacyId, 9, 'On', createdByUserId) // autopilot
607608
return legacyId
608609
}
609610

@@ -684,6 +685,8 @@ async function processMessage (message) {
684685
logger.info('Activating challenge...')
685686
const activated = await activateChallenge(legacyId)
686687
logger.info(`Activated! ${JSON.stringify(activated)}`)
688+
// make sure autopilot is on
689+
await metadataService.createOrUpdateMetadata(legacyId, 9, 'On', createdByUserId) // autopilot
687690
// Repost all challenge resource on Kafka so they will get created on legacy by the legacy-challenge-resource-processor
688691
await rePostResourcesOnKafka(challengeUuid, m2mToken)
689692
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* timeline notification Service
3+
* Interacts with InformixDB
4+
*/
5+
const util = require('util')
6+
const logger = require('../common/logger')
7+
const helper = require('../common/helper')
8+
9+
const QUERY_GET_ENTRY = 'SELECT notification_type_id FROM notification WHERE external_ref_id = %d AND project_id = %d'
10+
const QUERY_DELETE = 'DELETE FROM notification WHERE external_ref_id = ? AND project_id = ?'
11+
12+
/**
13+
* Prepare Informix statement
14+
* @param {Object} connection the Informix connection
15+
* @param {String} sql the sql
16+
* @return {Object} Informix statement
17+
*/
18+
async function prepare (connection, sql) {
19+
// logger.debug(`Preparing SQL ${sql}`)
20+
const stmt = await connection.prepareAsync(sql)
21+
return Promise.promisifyAll(stmt)
22+
}
23+
24+
/**
25+
* Get entry
26+
* @param {Number} legacyId the legacy challenge ID
27+
* @param {String} userId the userId
28+
*/
29+
async function getEntry (legacyId, userId) {
30+
const connection = await helper.getInformixConnection()
31+
let result = null
32+
try {
33+
result = await connection.queryAsync(util.format(QUERY_GET_ENTRY, userId, legacyId))
34+
} catch (e) {
35+
logger.error(`Error in 'getEntry' ${e}`)
36+
throw e
37+
} finally {
38+
await connection.closeAsync()
39+
}
40+
return result
41+
}
42+
43+
/**
44+
* Disable timeline notifications
45+
* @param {Number} legacyId the legacy challenge ID
46+
* @param {String} userId the userId
47+
*/
48+
async function disableTimelineNotifications (legacyId, userId) {
49+
const connection = await helper.getInformixConnection()
50+
let result = null
51+
try {
52+
await connection.beginTransactionAsync()
53+
const [existing] = await getEntry(legacyId, userId)
54+
if (existing) {
55+
const query = await prepare(connection, QUERY_DELETE)
56+
result = await query.executeAsync([userId, legacyId])
57+
}
58+
await connection.commitTransactionAsync()
59+
} catch (e) {
60+
logger.error(`Error in 'disableTimelineNotifications' ${e}, rolling back transaction`)
61+
await connection.rollbackTransactionAsync()
62+
throw e
63+
} finally {
64+
await connection.closeAsync()
65+
}
66+
return result
67+
}
68+
69+
module.exports = {
70+
getEntry,
71+
disableTimelineNotifications
72+
}

0 commit comments

Comments
 (0)