Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
participantNamesList = await DAO.retrieveAllParticipants()
} catch (err) {
Logger.error(`lib.Kafka.Cron.registerNewHandlers is unable to retrieve new participants: ${err}`)
}
if (participantNamesList && Array.isArray(participantNamesList)) {
for (let participantName of participantNamesList) {
// lets check to see if there is a Prepare Consumer for this partiticipant
let kafkaPrepareTopic = Utility.transformAccountToTopicName(participantName, TransferEventType.TRANSFER, TransferEventAction.PREPARE)
let isConsumerForPrepareTopicExist = false
try {
if (Consumer.getConsumer(kafkaPrepareTopic)) {
isConsumerForPrepareTopicExist = true
}
} catch (err) {
Logger.debug(`lib.Kafka.Cron.registerNewHandlers - participant ${participantName} for topic ${kafkaPrepareTopic} does not exist: ${err}`)
isConsumerForPrepareTopicExist = false
}
if (!isConsumerForPrepareTopicExist) {
Logger.info(`lib.Kafka.Cron.registerNewHandlers - Registering new PrepareHandler for participant ${participantName} for topic ${kafkaPrepareTopic} `)
const RegisterHandlers = require('../../register')
await RegisterHandlers.transfers.registerPrepareHandlers([participantName])
}
}
} else {
Logger.error(`lib.Kafka.Cron.registerNewHandlers - participantNamesList not a valid list. Skipping job for handlerType: ${handlerType}.`)
}
}
const isConnected = async topicName => {
const consumer = getConsumer(topicName)
const metadata = await getMetadataPromise(consumer, topicName)
const foundTopics = metadata.topics.map(topic => topic.name)
if (foundTopics.indexOf(topicName) === -1) {
Logger.debug(`Connected to consumer, but ${topicName} not found.`)
throw new Error(`Connected to consumer, but ${topicName} not found.`)
}
return true
}