Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/HLM-6407-template' into HLM-6407…
Browse files Browse the repository at this point in the history
…-template
  • Loading branch information
Priyanka-eGov committed Jul 25, 2024
2 parents 9224289 + e13a224 commit 232f6b2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion utilities/project-factory/src/server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getDBSchemaName = (dbSchema = "") => {
}
// Configuration object containing various environment variables
const config = {
isCallGenerateWhenDeliveryConditionsDiffer:true,
isCallGenerateWhenDeliveryConditionsDiffer: true,
enableDynamicTargetTemplate: true,
prefixForMicroplanCampaigns: "MP",
excludeHierarchyTypeFromBoundaryCodes: false,
Expand Down Expand Up @@ -62,6 +62,7 @@ const config = {
KAFKA_CREATE_GENERATED_RESOURCE_DETAILS_TOPIC: process.env.KAFKA_CREATE_GENERATED_RESOURCE_DETAILS_TOPIC || "create-generated-resource-details",
KAFKA_SAVE_PROCESS_TRACK_TOPIC: process.env.KAFKA_SAVE_PROCESS_TRACK_TOPIC || "save-process-track",
KAFKA_UPDATE_PROCESS_TRACK_TOPIC: process.env.KAFKA_UPDATE_PROCESS_TRACK_TOPIC || "update-process-track",
KAFKA_TEST_TOPIC: "test-topic-project-factory",
},

// Database configuration
Expand Down
3 changes: 2 additions & 1 deletion utilities/project-factory/src/server/kafka/Listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const kafkaConfig: ConsumerGroupOptions = {
// Topic Names
const topicNames = [
config.kafka.KAFKA_START_CAMPAIGN_MAPPING_TOPIC,
config.kafka.KAFKA_PROCESS_CAMPAIGN_MAPPING_TOPIC
config.kafka.KAFKA_PROCESS_CAMPAIGN_MAPPING_TOPIC,
config.kafka.KAFKA_TEST_TOPIC
];

// Consumer Group Initialization
Expand Down
24 changes: 24 additions & 0 deletions utilities/project-factory/src/server/kafka/Producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,33 @@ const kafkaClient = new KafkaClient({
// Creating a new Kafka producer instance using the Kafka client
const producer = new Producer(kafkaClient, { partitionerType: 2 }); // Using partitioner type 2

// Function to send a test message to check broker availability
const checkBrokerAvailability = () => {
const payloads = [
{
topic: config.kafka.KAFKA_TEST_TOPIC,
messages: JSON.stringify({ message: 'Test message to check broker availability' }),
},
];

producer.send(payloads, (err, data) => {
if (err) {
if (err.message && err.message.toLowerCase().includes('broker not available')) {
logger.error('Broker not available. Shutting down the service.');
shutdownGracefully();
} else {
logger.error('Error sending test message:', err);
}
} else {
logger.info('Test message sent successfully:', data);
}
});
};

// Event listener for 'ready' event, indicating that the producer is ready to send messages
producer.on('ready', () => {
logger.info('Producer is ready'); // Log message indicating producer is ready
checkBrokerAvailability(); // Check broker availability by sending a test message
});

// Event listener for 'error' event, indicating that the producer encountered an error
Expand Down
3 changes: 2 additions & 1 deletion utilities/project-factory/src/server/utils/generateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function extractProperties(obj: any) {
}

function areBoundariesSame(existingBoundaries: any, currentBoundaries: any) {
if (!existingBoundaries || !currentBoundaries) return false;
if (existingBoundaries.length !== currentBoundaries.length) return false;
const existingSetOfBoundaries = new Set(existingBoundaries.map((exboundary: any) => JSON.stringify(extractProperties(exboundary))));
const currentSetOfBoundaries = new Set(currentBoundaries.map((currboundary: any) => JSON.stringify(extractProperties(currboundary))));
Expand Down Expand Up @@ -81,4 +82,4 @@ async function callGenerate(request: any, type: any) {



export { callGenerateIfBoundariesDiffer, callGenerate }
export { callGenerateIfBoundariesDiffer, callGenerate }
1 change: 1 addition & 0 deletions utilities/project-factory/src/server/utils/targetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async function generateDynamicTargetHeaders(request: any, campaignObject: any, l
}
else {
headerColumnsAfterHierarchy = await getConfigurableColumnHeadersBasedOnCampaignType(request);
headerColumnsAfterHierarchy.shift();
}
return headerColumnsAfterHierarchy;
}
Expand Down

0 comments on commit 232f6b2

Please sign in to comment.