Skip to content

Commit cc65645

Browse files
author
Hamid Tavakoli
authored
Merge pull request #67 from topcoder-platform/standardLint
Standard lint
2 parents 506ba41 + c65d135 commit cc65645

19 files changed

+710
-373
lines changed

.circleci/config.yml

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
version: 2
22
defaults: &defaults
3-
docker:
4-
- image: circleci/python:2.7-stretch-browsers
3+
docker:
4+
- image: circleci/python:2.7-stretch-browsers
55
install_dependency: &install_dependency
6-
name: Installation of build and deployment dependencies.
7-
command: |
8-
sudo apt install jq
9-
sudo pip install awscli --upgrade
10-
sudo pip install docker-compose
11-
6+
name: Installation of build and deployment dependencies.
7+
command: |
8+
sudo apt install jq
9+
sudo pip install awscli --upgrade
10+
sudo pip install docker-compose
11+
1212
install_deploysuite: &install_deploysuite
13-
name: Installation of install_deploysuite.
14-
#Git Clone -change back to v1.3 or latest once counter var is generalized.
15-
command: |
16-
git clone --branch master https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
17-
cp ./../buildscript/master_deploy.sh .
18-
cp ./../buildscript/buildenv.sh .
19-
cp ./../buildscript/awsconfiguration.sh .
20-
13+
name: Installation of install_deploysuite.
14+
#Git Clone -change back to v1.3 or latest once counter var is generalized.
15+
command: |
16+
git clone --branch master https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
17+
cp ./../buildscript/master_deploy.sh .
18+
cp ./../buildscript/buildenv.sh .
19+
cp ./../buildscript/awsconfiguration.sh .
20+
2121
restore_cache_settings_for_build: &restore_cache_settings_for_build
2222
key: circleci-tc-email-service-{{ checksum "package-lock.json" }}
2323

@@ -27,9 +27,8 @@ save_cache_settings: &save_cache_settings
2727
- node_modules
2828

2929
run_build: &run_build
30-
name: Build of Docker image
31-
command: ./build.sh
32-
30+
name: Build of Docker image
31+
command: ./build.sh
3332

3433
jobs:
3534
# Build & Deploy against development backend rer
@@ -45,14 +44,13 @@ jobs:
4544
- save_cache: *save_cache_settings
4645
- deploy:
4746
name: Running Masterscript - deploy tc-email-service
48-
command: |
47+
command: |
4948
./awsconfiguration.sh DEV
5049
source awsenvconf
5150
./buildenv.sh -e DEV -b dev-tc-email-service-deployvar
5251
source buildenvvar
53-
./master_deploy.sh -d ECS -e DEV -t latest -s dev-global-appvar,dev-tc-email-service-appvar -i tc-email-service -p FARGATE
54-
55-
52+
./master_deploy.sh -d ECS -e DEV -t latest -s dev-global-appvar,dev-tc-email-service-appvar -i tc-email-service -p FARGATE
53+
5654
"build-prod":
5755
<<: *defaults
5856
steps:
@@ -70,21 +68,20 @@ jobs:
7068
source awsenvconf
7169
./buildenv.sh -e PROD -b prod-tc-email-service-deployvar
7270
source buildenvvar
73-
./master_deploy.sh -d ECS -e PROD -t latest -s prod-global-appvar,prod-tc-email-service-appvar -i tc-email-service -p FARGATE
71+
./master_deploy.sh -d ECS -e PROD -t latest -s prod-global-appvar,prod-tc-email-service-appvar -i tc-email-service
7472
75-
7673
workflows:
7774
version: 2
7875
build:
7976
jobs:
8077
# Development builds are executed on "develop" branch only.
8178
- "build-dev":
82-
context : org-global
79+
context: org-global
8380
filters:
8481
branches:
85-
only: ['dev', 'feature/decouple-sendgridtemplateid']
82+
only: ["dev", "feature/decouple-sendgridtemplateid"]
8683
- "build-prod":
87-
context : org-global
84+
context: org-global
8885
filters:
8986
branches:
9087
only: master

.eslintrc.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

config/default.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ module.exports = {
1111
dialect: 'postgres',
1212
logging: false,
1313
dialectOptions: {
14-
ssl: process.env.DATABASE_SSL != null,
14+
ssl: process.env.DATABASE_SSL != null
1515
},
1616
pool: {
1717
max: 5,
1818
min: 0,
19-
idle: 10000,
20-
},
19+
idle: 10000
20+
}
2121
},
2222
DISABLE_LOGGING: process.env.DISABLE_LOGGING || 'false',
2323

@@ -29,8 +29,9 @@ module.exports = {
2929

3030
KAFKA_GROUP_ID: process.env.KAFKA_GROUP_ID,
3131
KAFKA_CLIENT_CERT: process.env.KAFKA_CLIENT_CERT ? process.env.KAFKA_CLIENT_CERT.replace('\\n', '\n') : null,
32-
KAFKA_CLIENT_CERT_KEY: process.env.KAFKA_CLIENT_CERT_KEY ?
33-
process.env.KAFKA_CLIENT_CERT_KEY.replace('\\n', '\n') : null,
32+
KAFKA_CLIENT_CERT_KEY: process.env.KAFKA_CLIENT_CERT_KEY
33+
? process.env.KAFKA_CLIENT_CERT_KEY.replace('\\n', '\n')
34+
: null,
3435

3536
// mapping from event type to sendgrid email template id
3637
TEMPLATE_MAP: process.env.TEMPLATE_MAP,
@@ -41,16 +42,16 @@ module.exports = {
4142
EMAIL_MAX_ERRORS: process.env.EMAIL_MAX_ERRORS || 2,
4243
EMAIL_PAUSE_TIME: process.env.EMAIL_PAUSE_TIME || 30,
4344

44-
//in every 2 minutes will retry for failed status
45+
// in every 2 minutes will retry for failed status
4546
EMAIL_RETRY_SCHEDULE: process.env.EMAIL_RETRY_SCHEDULE || '0 */2 * * * *',
46-
//wont't retry failed emails older than this time (msec)
47+
// wont't retry failed emails older than this time (msec)
4748
EMAIL_RETRY_MAX_AGE: process.env.EMAIL_RETRY_MAX_AGE || 1000 * 60 * 60 * 24,
4849

4950
API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || '/v5/email',
5051

5152
PAYLOAD_SENDGRID_TEMPLATE_KEY: process.env.PAYLOAD_SENDGRID_TEMPLATE_KEY || 'sendgrid_template_id',
52-
//Tracing information
53+
// Tracing information
5354
APM_OTLP_TRACE_EXPORTER_URL: process.env.APM_OTLP_TRACE_EXPORTER_URL || '',
5455
APM_SERVICE_NAME: process.env.APM_SERVICE_NAME || 'tc-email-service-svc',
55-
APM_TRACER_NAME: process.env.APM_TRACER_NAME || 'tc-email-service-svc',
56-
};
56+
APM_TRACER_NAME: process.env.APM_TRACER_NAME || 'tc-email-service-svc'
57+
}

config/development.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
*/
44
module.exports = {
55
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
6-
PORT: process.env.PORT || 4000,
7-
};
6+
PORT: process.env.PORT || 4000
7+
}

config/production.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
module.exports = {
55
LOG_LEVEL: process.env.LOG_LEVEL || 'error',
66
PORT: process.env.PORT || 4000,
7-
DISABLE_LOGGING: process.env.DISABLE_LOGGING || 'true',
8-
};
7+
DISABLE_LOGGING: process.env.DISABLE_LOGGING || 'true'
8+
}

config/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
*/
44
module.exports = {
55
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
6-
PORT: process.env.PORT || 4000,
7-
};
6+
PORT: process.env.PORT || 4000
7+
}

connect/connectEmailServer.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
/**
22
* This is TopCoder connect email server.
33
*/
4-
const _ = require('lodash');
5-
const config = require('config');
6-
const emailServer = require('../index');
7-
const service = require('./service');
8-
const logger = require('../src/common/logger');
4+
const _ = require('lodash')
5+
const config = require('config')
6+
const emailServer = require('../index')
7+
const service = require('./service')
8+
const logger = require('../src/common/logger')
99

1010
// set configuration for the server, see ../config/default.js for available config parameters
1111
// setConfig should be called before initDatabase and start functions
12-
emailServer.setConfig({ LOG_LEVEL: config.LOG_LEVEL });
12+
emailServer.setConfig({ LOG_LEVEL: config.LOG_LEVEL })
1313

1414
// add topic handlers,
1515
// handler is used build a notification list for a message of a topic,
1616
// it is defined as: function(topic, message),
1717
// the topic is topic name,
1818
// the message is JSON event message,
1919
const handler = async (topic, message) => {
20-
let templateId = config.TEMPLATE_MAP[topic];
21-
templateId = _.get(message, config.PAYLOAD_SENDGRID_TEMPLATE_KEY, templateId);
20+
let templateId = config.TEMPLATE_MAP[topic]
21+
templateId = _.get(message, config.PAYLOAD_SENDGRID_TEMPLATE_KEY, templateId)
2222
if (!templateId) {
23-
return { success: false, error: `Template not found for topic ${topic}` };
23+
return { success: false, error: `Template not found for topic ${topic}` }
2424
}
2525

2626
try {
2727
await service.sendEmail(templateId, message)
28-
return { success: true };
28+
return { success: true }
2929
} catch (err) {
30-
logger.error("Error occurred in sendgrid api calling:", err);
31-
return { success: false, error: err };
30+
logger.error('Error occurred in sendgrid api calling:', err)
31+
return { success: false, error: err }
3232
}
33-
34-
};
33+
}
3534

3635
// init all events
3736
_.keys(config.TEMPLATE_MAP).forEach((eventType) => {
38-
emailServer.addTopicHandler(eventType, handler);
39-
});
37+
emailServer.addTopicHandler(eventType, handler)
38+
})
4039

4140
// init database, it will clear and re-create all tables
4241
emailServer
@@ -47,9 +46,9 @@ emailServer
4746
emailServer.start()
4847
})
4948
.catch((e) => {
50-
logger.error('Error occurred in starting email server:', e);
51-
process.exit(1);
52-
}); // eslint-disable-line no-console
49+
logger.error('Error occurred in starting email server:', e)
50+
process.exit(1)
51+
}) // eslint-disable-line no-console
5352

5453
// if no need to init database, then directly start the server:
55-
// emailServer.start()
54+
// emailServer.start()

connect/service.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
* This is TopCoder connect email service.
33
*/
44

5-
const sgMail = require('@sendgrid/mail');
6-
const config = require('config');
7-
const logger = require('../src/common/logger');
5+
const sgMail = require('@sendgrid/mail')
6+
const config = require('config')
7+
const logger = require('../src/common/logger')
88

99
// set api key for SendGrid email client
10-
sgMail.setApiKey(config.SENDGRID_API_KEY);
10+
sgMail.setApiKey(config.SENDGRID_API_KEY)
1111

1212
const sendEmail = async (templateId, message) => { // send email
13-
const span = await logger.startSpan('sendEmail');
13+
const span = await logger.startSpan('sendEmail')
1414
let msg = {}
15-
const from = message.from ? message.from : config.EMAIL_FROM;
16-
const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM;
17-
const substitutions = message.data;
18-
const categories = message.categories ? message.categories : [];
19-
const to = message.recipients;
20-
const cc = message.cc ? message.cc : [];
21-
const bcc = message.bcc ? message.bcc : [];
22-
const sendAt = message.sendAt ? message.sendAt : undefined;
15+
const from = message.from ? message.from : config.EMAIL_FROM
16+
const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM
17+
const substitutions = message.data
18+
const categories = message.categories ? message.categories : []
19+
const to = message.recipients
20+
const cc = message.cc ? message.cc : []
21+
const bcc = message.bcc ? message.bcc : []
22+
const sendAt = message.sendAt ? message.sendAt : undefined
2323
const personalizations = message.personalizations ? message.personalizations : undefined
24-
const attachments = message.attachments ? message.attachments : [];
24+
const attachments = message.attachments ? message.attachments : []
2525

26-
if (message.version && message.version == "v3") {
26+
if (message.version && message.version === 'v3') {
2727
msg = {
2828
to,
2929
templateId,
@@ -36,7 +36,7 @@ const sendEmail = async (templateId, message) => { // send email
3636
bcc,
3737
attachments,
3838
sendAt
39-
};
39+
}
4040
} else {
4141
msg = {
4242
to,
@@ -47,23 +47,23 @@ const sendEmail = async (templateId, message) => { // send email
4747
replyTo,
4848
categories,
4949
cc,
50-
bcc,
51-
};
50+
bcc
51+
}
5252
}
53-
logger.info(`Sending email with templateId: ${templateId} and message: ${JSON.stringify(msg)}`);
53+
logger.info(`Sending email with templateId: ${templateId} and message: ${JSON.stringify(msg)}`)
5454
try {
55-
await logger.endSpan(span);
56-
const sgSpan = await logger.startSpan('sendgrid');
55+
await logger.endSpan(span)
56+
const sgSpan = await logger.startSpan('sendgrid')
5757
const result = await sgMail.send(msg)
58-
await logger.endSpan(sgSpan);
59-
logger.info(`Email sent successfully with result: ${JSON.stringify(result)} \n ${JSON.stringify(msg)}`);
58+
await logger.endSpan(sgSpan)
59+
logger.info(`Email sent successfully with result: ${JSON.stringify(result)} \n ${JSON.stringify(msg)}`)
6060
return result
6161
} catch (err) {
62-
logger.error(`Error occurred in sendgrid api calling: ${err}`);
62+
logger.error(`Error occurred in sendgrid api calling: ${err}`)
6363
throw err
6464
}
6565
}
6666
module.exports = {
67-
sendEmail,
67+
sendEmail
6868
}
69-
logger.buildService(module.exports)
69+
logger.buildService(module.exports)

0 commit comments

Comments
 (0)