Skip to content

Feature/version support #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ module.exports = {
//in every 2 minutes will retry for failed status
EMAIL_RETRY_SCHEDULE: process.env.EMAIL_RETRY_SCHEDULE || '0 */2 * * * *',

API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || 'email',
API_VERSION: process.env.API_VERSION || 'v5',
API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || '/v5/email',

};
7 changes: 1 addition & 6 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ EMAIL_RETRY_SCHEDULE=$(eval "echo \"\$${ENV}_EMAIL_RETRY_SCHEDULE\"")
DISABLE_LOGGING=$(eval "echo \$${ENV}_DISABLE_LOGGING")

API_CONTEXT_PATH=$(eval "echo \$${ENV}_API_CONTEXT_PATH")
API_VERSION=$(eval "echo \$${ENV}_API_VERSION")

configure_aws_cli() {
aws --version
Expand Down Expand Up @@ -195,10 +194,6 @@ make_task_def(){
{
"name": "API_CONTEXT_PATH",
"value": "%s"
},
{
"name": "API_VERSION",
"value": "%s"
}
],
"portMappings": [
Expand All @@ -220,7 +215,7 @@ make_task_def(){
]
}'

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)
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)

}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"pg": "^7.3.0",
"sequelize": "^4.21.0",
"superagent": "^3.8.0",
"tc-core-library-js": "gondzo/tc-core-library-js.git#dev",
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.2",
"winston": "^2.4.0"
},
"engines": {
Expand Down
53 changes: 26 additions & 27 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,27 @@ function configureKafkaConsumer(handlers) {
// emailTries[topicName] += 1; //temporary disabling this feature
emailModel.status = 'FAILED';
return emailModel.save().then(() => {
/*
* temporary disabling this feature as there is chance of losing message during
* unsubscribe/pausing due to simple kafka consumer
*/
/*
const currentTries = emailTries[topicName];
if (currentTries > maxErrors) {
logger.debug(`Failed to send email. Will sleep for ${pauseTime}s`);
emailTries[topicName] = 0;
schedule.scheduleJob(new Date(now.getTime() + pauseTime * 1000), () => {
consumer.subscribe(topic, dataHandler);
});
return consumer.unsubscribe(topic, partition).then(() => {
throw result.error
});
} else {
logger.debug(`Failed to send email (retries left ${maxErrors - currentTries})`);
throw result.error;
}*/
/*
* temporary disabling this feature as there is chance of losing message during
* unsubscribe/pausing due to simple kafka consumer
*/
/*
const currentTries = emailTries[topicName];
if (currentTries > maxErrors) {
logger.debug(`Failed to send email. Will sleep for ${pauseTime}s`);
emailTries[topicName] = 0;

schedule.scheduleJob(new Date(now.getTime() + pauseTime * 1000), () => {
consumer.subscribe(topic, dataHandler);
});

return consumer.unsubscribe(topic, partition).then(() => {
throw result.error
});
} else {
logger.debug(`Failed to send email (retries left ${maxErrors - currentTries})`);
throw result.error;
}*/
});
}
}).then(() => consumer.commitOffset({ topic, partition, offset: m.offset })) // commit offset
Expand All @@ -124,9 +124,9 @@ function startKafkaConsumer(consumer, handlers, dataHandler) {
return consumer
.init()
.then(() => Promise.each(_.keys(handlers), (topicName) => { // add back the ignored topic prefix to use full topic name
emailTries[topicName] = 0;
return consumer.subscribe(`${config.KAFKA_TOPIC_IGNORE_PREFIX || ''}${topicName}`, dataHandler);
})
emailTries[topicName] = 0;
return consumer.subscribe(`${config.KAFKA_TOPIC_IGNORE_PREFIX || ''}${topicName}`, dataHandler);
})
);
}

Expand Down Expand Up @@ -189,8 +189,7 @@ function start(handlers) {
req.signature = `${def.controller}#${def.method}`;
next();
});
if ((url !== '/email/health')
&& (url !== `/${config.API_VERSION}/${config.API_CONTEXT_PATH}/health`)) {
if (url !== '/health') {
actions.push(jwtAuth());
actions.push((req, res, next) => {
if (!req.authUser) {
Expand All @@ -205,7 +204,7 @@ function start(handlers) {
});
});

app.use('/', apiRouter);
app.use(config.API_CONTEXT_PATH, apiRouter);

app.use((req, res) => {
res.status(404).json({ error: 'route not found' });
Expand Down
50 changes: 13 additions & 37 deletions src/routes.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
'use strict';

const config = require('config');

const routes = {};

const oldkeyEventType = '/email/templates/eventType/:name'
routes[oldkeyEventType] = {
get: {
controller: 'TemplateController',
method: 'eventTypes',
}
};

const oldkeyHealthCheck = '/email/health'
routes[oldkeyHealthCheck] = {
get: {
controller: 'HealthController',
method: 'health',
}
};

const keyEventType = `/${config.API_VERSION}/${config.API_CONTEXT_PATH}/templates/eventType/:name`;
routes[keyEventType] = {
get: {
controller: 'TemplateController',
method: 'eventTypes',
}
};

const keyHealthCheck = `/${config.API_VERSION}/${config.API_CONTEXT_PATH}/health`;
routes[keyHealthCheck] = {
get: {
controller: 'HealthController',
method: 'health',
}
module.exports = {
'/templates/:name': {
get: {
controller: 'TemplateController',
method: 'eventTypes',
},
},
'/health': {
get: {
controller: 'HealthController',
method: 'health',
},
},
};


module.exports = routes;