Skip to content

Commit

Permalink
Project bulk creation implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ashish-egov committed Jan 16, 2025
1 parent a364bdf commit f7ab7bc
Show file tree
Hide file tree
Showing 14 changed files with 365 additions and 579 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ CREATE TABLE eg_cm_campaign_projects (
createdby CHARACTER VARYING(128) NOT NULL,
lastmodifiedby CHARACTER VARYING(128) NOT NULL,
createdtime BIGINT NOT NULL,
lastmodifiedtime BIGINT NOT NULL
lastmodifiedtime BIGINT NOT NULL,
CONSTRAINT unique_campaign_boundary_active UNIQUE (campaignnumber, boundarycode, isactive)
);

-- Adding index on campaignnumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ CREATE TABLE eg_cm_campaign_creation_process_status (
createdby VARCHAR(128) NOT NULL,
lastmodifiedby VARCHAR(128) NOT NULL,
createdtime BIGINT NOT NULL,
lastmodifiedtime BIGINT NOT NULL
lastmodifiedtime BIGINT NOT NULL,
CONSTRAINT unique_campaign_process UNIQUE (campaignnumber, processname)
);

-- Adding index on campaignnumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ export const processTrackStatuses = {
failed: "failed",
}

export const processNamesConstants = {
export const processNamesConstantsInOrder = {
projectCreation: "project-creation"
}

export const campaignProcessStatus = {
inqueue : "inqueue",
started : "started",
failed : "failed",
completed : "completed"
Expand Down
4 changes: 2 additions & 2 deletions health-services/project-factory/src/server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ const config = {
KAFKA_SAVE_CAMPAIGN_PROJECT : process.env.KAFKA_SAVE_CAMPAIGN_PROJECT || "save-campaign-project",
KAFKA_UPDATE_CAMPAIGN_PROJECT : process.env.KAFKA_UPDATE_CAMPAIGN_PROJECT || "update-campaign-project",
KAFKA_PROCESS_HANDLER_TOPIC: process.env.KAFKA_PROCESS_HANDLER_TOPIC || "project-factory-process-handler",
KAFKA_SUB_PROCESS_HANDLER_TOPIC: process.env.KAFKA_SUB_PROCESS_HANDLER_TOPIC || "project-factory-sub-process-handler",
KAFKA_CREATE_CAMPAIGN_PROCESS_TOPIC: process.env.KAFKA_CREATE_CAMPAIGN_PROCESS_TOPIC || "create-campaign-process",
KAFKA_UPDATE_CAMPAIGN_PROCESS_TOPIC: process.env.KAFKA_UPDATE_CAMPAIGN_PROCESS_TOPIC || "update-campaign-process",
KAFKA_TEST_TOPIC: "test-topic-project-factory",
KAFKA_UPDATE_CAMPAIGN_PROCESS_TOPIC: process.env.KAFKA_UPDATE_CAMPAIGN_PROCESS_TOPIC || "update-campaign-process"
},

// Database configuration
Expand Down
9 changes: 6 additions & 3 deletions health-services/project-factory/src/server/kafka/Listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import config from '../config';
import { getFormattedStringForDebug, logger } from '../utils/logger';
import { shutdownGracefully } from '../utils/genericUtils';
import { handleCampaignMapping } from '../utils/campaignMappingUtils';
import { handleCampaignProcessing } from '../utils/campaignUtils';
import { handleCampaignProcessing, handleCampaignSubProcessing } from '../utils/campaignUtils';

// Kafka Configuration
const kafkaConfig: ConsumerGroupOptions = {
Expand All @@ -17,8 +17,8 @@ const kafkaConfig: ConsumerGroupOptions = {
// Topic Names
const topicNames = [
config.kafka.KAFKA_START_CAMPAIGN_MAPPING_TOPIC,
config.kafka.KAFKA_TEST_TOPIC,
config.kafka.KAFKA_PROCESS_HANDLER_TOPIC
config.kafka.KAFKA_PROCESS_HANDLER_TOPIC,
config.kafka.KAFKA_SUB_PROCESS_HANDLER_TOPIC
];

// Consumer Group Initialization
Expand All @@ -39,6 +39,9 @@ export function listener() {
case config.kafka.KAFKA_PROCESS_HANDLER_TOPIC:
handleCampaignProcessing(messageObject);
break;
case config.kafka.KAFKA_SUB_PROCESS_HANDLER_TOPIC:
handleCampaignSubProcessing(messageObject);
break;
default:
logger.warn(`Unhandled topic: ${message.topic}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { addBoundariesInProjectCampaign, getCampaignProjects, updateTargetsInProjectCampaign } from "../utils/projectCampaignUtils";
import { getAllBoundariesForCampaign } from "../utils/boundaryUtils";
import { getTargetListForCampaign, persistForProjectProcess } from "../utils/targetUtils";
import { getRootBoundaryCode, markProcessStatus } from "../utils/campaignUtils";
import { campaignProcessStatus, processNamesConstants } from "../config/constants";
import { getRootBoundaryCode } from "../utils/campaignUtils";
import { campaignProcessStatus, processNamesConstantsInOrder } from "../config/constants";
import { markProcessStatus } from "../utils/processTrackUtils";




const processProjectCreation = async (requestBody: any) => {
const processProjectCreation = async (campaignDetailsAndRequestInfo: any) => {
try {
const { CampaignDetails, RequestInfo } = requestBody;
const { CampaignDetails, RequestInfo } = campaignDetailsAndRequestInfo;
const { campaignNumber, boundaries, tenantId } = CampaignDetails;
await markProcessStatus(campaignNumber, processNamesConstants.projectCreation, campaignProcessStatus.started);
await markProcessStatus(campaignNumber, processNamesConstantsInOrder.projectCreation, campaignProcessStatus.started);
const allTargetList = await getTargetListForCampaign(CampaignDetails);
const allBoundaries = await getAllBoundariesForCampaign(CampaignDetails);
const campaignProjects: any[] = await getCampaignProjects(campaignNumber, true);
Expand All @@ -21,7 +22,7 @@ const processProjectCreation = async (requestBody: any) => {
await persistForProjectProcess([rootBoundaryCode], campaignNumber, tenantId, null);
} catch (error: any) {
console.log(error);
throw error;
await markProcessStatus(campaignDetailsAndRequestInfo?.CampaignDetails?.campaignNumber, processNamesConstantsInOrder.projectCreation, campaignProcessStatus.failed, error?.message);
}
};

Expand Down
Loading

0 comments on commit f7ab7bc

Please sign in to comment.