Skip to content

Commit 2b4c84d

Browse files
author
Sachin Maheshwari
committed
changes after finalizing endpoint naming convention.
1 parent ccfa799 commit 2b4c84d

File tree

3 files changed

+40
-66
lines changed

3 files changed

+40
-66
lines changed

config/default.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ module.exports = {
4141
//in every 2 minutes will retry for failed status
4242
EMAIL_RETRY_SCHEDULE: process.env.EMAIL_RETRY_SCHEDULE || '0 */2 * * * *',
4343

44-
API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || 'email',
45-
API_VERSION: process.env.API_VERSION || 'v5',
44+
API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || '/v5/email',
4645

4746
};

src/app.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,27 @@ function configureKafkaConsumer(handlers) {
7979
// emailTries[topicName] += 1; //temporary disabling this feature
8080
emailModel.status = 'FAILED';
8181
return emailModel.save().then(() => {
82-
/*
83-
* temporary disabling this feature as there is chance of losing message during
84-
* unsubscribe/pausing due to simple kafka consumer
85-
*/
86-
/*
87-
const currentTries = emailTries[topicName];
88-
if (currentTries > maxErrors) {
89-
logger.debug(`Failed to send email. Will sleep for ${pauseTime}s`);
90-
emailTries[topicName] = 0;
91-
92-
schedule.scheduleJob(new Date(now.getTime() + pauseTime * 1000), () => {
93-
consumer.subscribe(topic, dataHandler);
94-
});
95-
96-
return consumer.unsubscribe(topic, partition).then(() => {
97-
throw result.error
98-
});
99-
} else {
100-
logger.debug(`Failed to send email (retries left ${maxErrors - currentTries})`);
101-
throw result.error;
102-
}*/
82+
/*
83+
* temporary disabling this feature as there is chance of losing message during
84+
* unsubscribe/pausing due to simple kafka consumer
85+
*/
86+
/*
87+
const currentTries = emailTries[topicName];
88+
if (currentTries > maxErrors) {
89+
logger.debug(`Failed to send email. Will sleep for ${pauseTime}s`);
90+
emailTries[topicName] = 0;
91+
92+
schedule.scheduleJob(new Date(now.getTime() + pauseTime * 1000), () => {
93+
consumer.subscribe(topic, dataHandler);
94+
});
95+
96+
return consumer.unsubscribe(topic, partition).then(() => {
97+
throw result.error
98+
});
99+
} else {
100+
logger.debug(`Failed to send email (retries left ${maxErrors - currentTries})`);
101+
throw result.error;
102+
}*/
103103
});
104104
}
105105
}).then(() => consumer.commitOffset({ topic, partition, offset: m.offset })) // commit offset
@@ -124,9 +124,9 @@ function startKafkaConsumer(consumer, handlers, dataHandler) {
124124
return consumer
125125
.init()
126126
.then(() => Promise.each(_.keys(handlers), (topicName) => { // add back the ignored topic prefix to use full topic name
127-
emailTries[topicName] = 0;
128-
return consumer.subscribe(`${config.KAFKA_TOPIC_IGNORE_PREFIX || ''}${topicName}`, dataHandler);
129-
})
127+
emailTries[topicName] = 0;
128+
return consumer.subscribe(`${config.KAFKA_TOPIC_IGNORE_PREFIX || ''}${topicName}`, dataHandler);
129+
})
130130
);
131131
}
132132

@@ -189,8 +189,7 @@ function start(handlers) {
189189
req.signature = `${def.controller}#${def.method}`;
190190
next();
191191
});
192-
if ((url !== '/email/health')
193-
&& (url !== `/${config.API_VERSION}/${config.API_CONTEXT_PATH}/health`)) {
192+
if (url !== '/health') {
194193
actions.push(jwtAuth());
195194
actions.push((req, res, next) => {
196195
if (!req.authUser) {
@@ -205,7 +204,7 @@ function start(handlers) {
205204
});
206205
});
207206

208-
app.use('/', apiRouter);
207+
app.use(config.API_CONTEXT_PATH, apiRouter);
209208

210209
app.use((req, res) => {
211210
res.status(404).json({ error: 'route not found' });

src/routes.js

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,16 @@
11
'use strict';
22

3-
const config = require('config');
4-
5-
const routes = {};
6-
7-
const oldkeyEventType = '/email/templates/eventType/:name'
8-
routes[oldkeyEventType] = {
9-
get: {
10-
controller: 'TemplateController',
11-
method: 'eventTypes',
12-
}
13-
};
14-
15-
const oldkeyHealthCheck = '/email/health'
16-
routes[oldkeyHealthCheck] = {
17-
get: {
18-
controller: 'HealthController',
19-
method: 'health',
20-
}
21-
};
22-
23-
const keyEventType = `/${config.API_VERSION}/${config.API_CONTEXT_PATH}/templates/eventType/:name`;
24-
routes[keyEventType] = {
25-
get: {
26-
controller: 'TemplateController',
27-
method: 'eventTypes',
28-
}
29-
};
30-
31-
const keyHealthCheck = `/${config.API_VERSION}/${config.API_CONTEXT_PATH}/health`;
32-
routes[keyHealthCheck] = {
33-
get: {
34-
controller: 'HealthController',
35-
method: 'health',
36-
}
3+
module.exports = {
4+
'/templates/:name': {
5+
get: {
6+
controller: 'TemplateController',
7+
method: 'eventTypes',
8+
},
9+
},
10+
'/health': {
11+
get: {
12+
controller: 'HealthController',
13+
method: 'health',
14+
},
15+
},
3716
};
38-
39-
40-
module.exports = routes;

0 commit comments

Comments
 (0)