Skip to content

Commit 9daea63

Browse files
Ignore messages from configured originators
1 parent 740cdec commit 9daea63

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

config/default.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,7 @@ module.exports = {
3535
GET_PROJECT_API_BASE: process.env.GET_PROJECT_API_BASE || 'http://localhost:4000/v5/projects',
3636
SEARCH_MEMBERS_API_BASE: process.env.SEARCH_MEMBERS_API_BASE || 'https://api.topcoder-dev.com/v3/members/_search',
3737
RESOURCES_API: process.env.RESOURCES_API || 'http://localhost:4000/v5/resources',
38-
CHALLENGE_API: process.env.CHALLENGE_API || 'http://localhost:4000/v5/challenges'
38+
CHALLENGE_API: process.env.CHALLENGE_API || 'http://localhost:4000/v5/challenges',
39+
40+
IGNORED_ORIGINATORS: process.env.IGNORED_ORIGINATORS ? process.env.IGNORED_ORIGINATORS.split(',') : ['legacy-migration-script']
3941
}

src/app.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
global.Promise = require('bluebird')
66
const config = require('config')
77
const Kafka = require('no-kafka')
8+
const _ = require('lodash')
89
const healthcheck = require('topcoder-healthcheck-dropin')
910
const logger = require('./common/logger')
1011
const helper = require('./common/helper')
@@ -34,14 +35,18 @@ const dataHandler = (messageSet, topic, partition) => Promise.each(messageSet, (
3435
}
3536

3637
return (async () => {
37-
if (topic === config.CHALLENGE_CREATE_TOPIC) {
38-
await ProcessorService.handleChallengeCreate(messageJSON)
39-
} else if (topic === config.PROJECT_MEMBER_ADDED_TOPIC) {
40-
await ProcessorService.handleMemberAdded(messageJSON)
41-
} else if (topic === config.PROJECT_MEMBER_REMOVED_TOPIC) {
42-
await ProcessorService.handleMemberRemoved(messageJSON)
38+
if (_.includes(config.IGNORED_ORIGINATORS, messageJSON.originator)) {
39+
logger.error(`The message originator is in the ignored list. Originator: ${messageJSON.originator}`)
40+
} else {
41+
if (topic === config.CHALLENGE_CREATE_TOPIC) {
42+
await ProcessorService.handleChallengeCreate(messageJSON)
43+
} else if (topic === config.PROJECT_MEMBER_ADDED_TOPIC) {
44+
await ProcessorService.handleMemberAdded(messageJSON)
45+
} else if (topic === config.PROJECT_MEMBER_REMOVED_TOPIC) {
46+
await ProcessorService.handleMemberRemoved(messageJSON)
47+
}
48+
logger.debug('Successfully processed message')
4349
}
44-
logger.debug('Successfully processed message')
4550
})()
4651
// commit offset
4752
.then(() => consumer.commitOffset({ topic, partition, offset: m.offset }))

0 commit comments

Comments
 (0)