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

update the retry logic #25

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The following parameters can be set in config files or in env variables:
- KAFKA_GROUP_ID: the Kafka group id, default value is 'legacy-challenge-processor'
- KAFKA_ERROR_TOPIC: The kafka error topic.
- BUSAPI_URL: Bus API URL
- MAX_RETRIES: the number of max retries; default value: 3
- RETRY_TIMEOUT: The timeout to retry processing the same message
- CREATE_CHALLENGE_TOPIC: the create challenge Kafka message topic, default value is 'challenge.notification.create'
- UPDATE_CHALLENGE_TOPIC: the update challenge Kafka message topic, default value is 'challenge.notification.update'
Expand Down
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
KAFKA_GROUP_ID: process.env.KAFKA_GROUP_ID || 'legacy-challenge-processor',
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'common.error.reporting',
BUSAPI_URL: process.env.BUSAPI_URL || 'https://api.topcoder-dev.com/v5',
MAX_RETRIES: process.env.MAX_RETRIES || 3,
RETRY_TIMEOUT: process.env.RETRY_TIMEOUT || 10 * 1000,

// Topics to listen
Expand Down
19 changes: 13 additions & 6 deletions src/services/ProcessorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,19 @@ async function processUpdate (message) {
// postponne kafka event
logger.info('Challenge does not exist yet. Will post the same message back to the bus API')
logger.error(`Error: ${JSON.stringify(e)}`)
// await new Promise((resolve) => {
// setTimeout(async () => {
// await helper.postBusEvent(config.UPDATE_CHALLENGE_TOPIC, message.payload)
// resolve()
// }, config.RETRY_TIMEOUT)
// })

const retryCountIdentifier = `${config.KAFKA_GROUP_ID.split(' ').join('_')}_retry_count`
let currentRetryCount = parseInt(get(messageJSON.payload, retryCountIdentifier, 1), 10)
if (currentRetryCount <= config.MAX_RETRIES) {
await new Promise((resolve) => {
setTimeout(async () => {
await helper.postBusEvent(config.UPDATE_CHALLENGE_TOPIC, { ...messageJSON.payload, [retryCountIdentifier]: currentRetryCount })
resolve()
}, config.RETRY_TIMEOUT * currentRetryCount)
})
} else {
logger.error(`Failed to process message after ${config.MAX_RETRIES} retries. Aborting...`)
}
return
}

Expand Down