Skip to content

Commit c2c571f

Browse files
author
sachin-maheshwari
authored
Merge pull request #7 from topcoder-platform/feature/version-support
Feature/version support
2 parents 31f7b1e + 99e0691 commit c2c571f

File tree

5 files changed

+42
-73
lines changed

5 files changed

+42
-73
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
};

deploy.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ EMAIL_RETRY_SCHEDULE=$(eval "echo \"\$${ENV}_EMAIL_RETRY_SCHEDULE\"")
6767
DISABLE_LOGGING=$(eval "echo \$${ENV}_DISABLE_LOGGING")
6868

6969
API_CONTEXT_PATH=$(eval "echo \$${ENV}_API_CONTEXT_PATH")
70-
API_VERSION=$(eval "echo \$${ENV}_API_VERSION")
7170

7271
configure_aws_cli() {
7372
aws --version
@@ -195,10 +194,6 @@ make_task_def(){
195194
{
196195
"name": "API_CONTEXT_PATH",
197196
"value": "%s"
198-
},
199-
{
200-
"name": "API_VERSION",
201-
"value": "%s"
202197
}
203198
],
204199
"portMappings": [
@@ -220,7 +215,7 @@ make_task_def(){
220215
]
221216
}'
222217

223-
task_def=$(printf "$task_template" $family $AWS_ACCOUNT_ID $AWS_ECS_CONTAINER_NAME $AWS_ACCOUNT_ID $AWS_REGION $AWS_REPOSITORY $TAG $ENV $AUTH_DOMAIN $AUTH_SECRET $DATABASE_URL $EMAIL_FROM "$JWKS_URI" "$KAFKA_CLIENT_CERT" "$KAFKA_CLIENT_CERT_KEY" $KAFKA_GROUP_ID $KAFKA_URL $LOG_LEVEL $PORT $SENDGRID_API_KEY "$TEMPLATE_MAP" "$VALID_ISSUERS" $EMAIL_MAX_ERRORS $EMAIL_PAUSE_TIME "$EMAIL_RETRY_SCHEDULE" "$DISABLE_LOGGING" "$API_CONTEXT_PATH" "$API_VERSION" $PORT $PORT $AWS_ECS_CLUSTER $AWS_REGION $ENV)
218+
task_def=$(printf "$task_template" $family $AWS_ACCOUNT_ID $AWS_ECS_CONTAINER_NAME $AWS_ACCOUNT_ID $AWS_REGION $AWS_REPOSITORY $TAG $ENV $AUTH_DOMAIN $AUTH_SECRET $DATABASE_URL $EMAIL_FROM "$JWKS_URI" "$KAFKA_CLIENT_CERT" "$KAFKA_CLIENT_CERT_KEY" $KAFKA_GROUP_ID $KAFKA_URL $LOG_LEVEL $PORT $SENDGRID_API_KEY "$TEMPLATE_MAP" "$VALID_ISSUERS" $EMAIL_MAX_ERRORS $EMAIL_PAUSE_TIME "$EMAIL_RETRY_SCHEDULE" "$DISABLE_LOGGING" "$API_CONTEXT_PATH" $PORT $PORT $AWS_ECS_CLUSTER $AWS_REGION $ENV)
224219

225220
}
226221

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"pg": "^7.3.0",
3939
"sequelize": "^4.21.0",
4040
"superagent": "^3.8.0",
41-
"tc-core-library-js": "gondzo/tc-core-library-js.git#dev",
41+
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.2",
4242
"winston": "^2.4.0"
4343
},
4444
"engines": {

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)