Skip to content

Commit

Permalink
Issue #38 - Commit offset when there"s a processing error
Browse files Browse the repository at this point in the history
  • Loading branch information
callmekatootie committed Jun 7, 2021
1 parent 03a0547 commit 0c4a964
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,36 @@ const dataHandler = (messageSet, topic, partition) => Promise.each(messageSet, (
} catch (e) {
logger.error('Invalid message JSON.')
logger.error(e)

// ignore the message
return
return co(function * () {
yield consumer.commitOffset({ topic, partition, offset: m.offset })
})
}

if (messageJSON.topic !== topic) {
logger.error(`The message topic ${messageJSON.topic} doesn't match the Kafka topic ${topic}.`)
// ignore the message
return
return co(function * () {
yield consumer.commitOffset({ topic, partition, offset: m.offset })
})
}

// Process only messages with scanned status
if (messageJSON.topic === config.AVSCAN_TOPIC && messageJSON.payload.status !== 'scanned') {
logger.debug(`Ignoring message in topic ${messageJSON.topic} with status ${messageJSON.payload.status}`)
// ignore the message
return
return co(function * () {
yield consumer.commitOffset({ topic, partition, offset: m.offset })
})
}

if (topic === config.SUBMISSION_CREATE_TOPIC && messageJSON.payload.fileType === 'url') {
logger.debug(`Ignoring message in topic ${messageJSON.topic} with file type as url`)
// ignore the message
return
return co(function * () {
yield consumer.commitOffset({ topic, partition, offset: m.offset })
})
}

return co(function * () {
Expand All @@ -66,11 +75,15 @@ const dataHandler = (messageSet, topic, partition) => Promise.each(messageSet, (
})
// commit offset regardless of errors
.then(() => {
consumer.commitOffset({ topic, partition, offset: m.offset })
return co(function * () {
yield consumer.commitOffset({ topic, partition, offset: m.offset })
})
})
.catch((err) => {
logger.error(err)
consumer.commitOffset({ topic, partition, offset: m.offset })
return co(function * () {
yield consumer.commitOffset({ topic, partition, offset: m.offset })
})
})
})

Expand Down

0 comments on commit 0c4a964

Please sign in to comment.