Skip to content

v5 and other miner changes #10

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 16 commits into from
Apr 10, 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
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# and runs it against the specified Topcoder backend (development or
# production) when container is executed.

FROM node:8.2.1
LABEL app="tc email" version="1.0"
FROM node:6.10
LABEL app="tc email" version="1.1"

WORKDIR /opt/app
COPY . .
RUN npm install
RUN npm install dotenv --save
#RUN npm install dotenv --save
RUN npm run lint
CMD ["npm", "start"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


## Dependencies
- nodejs https://nodejs.org/en/ (v8+)
- nodejs https://nodejs.org/en/ (v6+)
- Heroku Toolbelt https://toolbelt.heroku.com
- git
- PostgreSQL 9.5
Expand Down
3 changes: 3 additions & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ 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 || '/v5/email',

};
8 changes: 7 additions & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ EMAIL_PAUSE_TIME=$(eval "echo \$${ENV}_EMAIL_PAUSE_TIME")
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")

configure_aws_cli() {
aws --version
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
Expand Down Expand Up @@ -188,6 +190,10 @@ make_task_def(){
{
"name": "DISABLE_LOGGING",
"value": "%s"
},
{
"name": "API_CONTEXT_PATH",
"value": "%s"
}
],
"portMappings": [
Expand All @@ -209,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" $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
7 changes: 4 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ function configureKafkaConsumer(handlers) {
return null;
}
let emailModel = {};
const messageJSON = JSON.parse(message);
const busPayload = JSON.parse(message);
const messageJSON = busPayload.payload;
const handlerAsync = Promise.promisify(handler);
// use handler to create notification instances for each recipient
return models.Email.create(
Expand Down Expand Up @@ -189,7 +190,7 @@ function start(handlers) {
req.signature = `${def.controller}#${def.method}`;
next();
});
if (url !== '/email/health') {
if (url !== '/health') {
actions.push(jwtAuth());
actions.push((req, res, next) => {
if (!req.authUser) {
Expand All @@ -204,7 +205,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
2 changes: 1 addition & 1 deletion src/models/Email.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
module.exports = (sequelize, DataTypes) => sequelize.define('Email', {
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
topicName: { type: DataTypes.STRING, allowNull: true, field: 'topic_name' },
data: { type: DataTypes.STRING, allowNull: false },
data: { type: DataTypes.TEXT, allowNull: false },
recipients: { type: DataTypes.STRING, allowNull: false },
status: { type: DataTypes.STRING, allowNull: false },
}, {});
Expand Down
4 changes: 2 additions & 2 deletions src/routes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

module.exports = {
'/email/templates/eventType/:name': {
'/templates/:name': {
get: {
controller: 'TemplateController',
method: 'eventTypes',
},
},
'/email/health': {
'/health': {
get: {
controller: 'HealthController',
method: 'health',
Expand Down