Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 31f3aeb

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 7d764b5 + 4f29ba0 commit 31f3aeb

File tree

8 files changed

+45
-91
lines changed

8 files changed

+45
-91
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ The following config parameters are supported, they are defined in `config/defau
3232
|TC_DEV_ENV| the flag whether to use topcoder development api or production| false|
3333
| NEW_CHALLENGE_TEMPLATE | the body template for new challenge request. You can change the subTrack, reviewTypes, technologies, .. here | see `default.js` |
3434
| NEW_CHALLENGE_DURATION_IN_DAYS | the duration of new challenge | 5 |
35-
| NODE_MAILER_OPTIONS| the node mailer smtp options, see [here](https://nodemailer.com/smtp/ for more detail)| see `default.js` |
36-
|EMAIL_SENDER_ADDRESS| the email sender email address||
37-
|ISSUE_BID_EMAIL_RECEIVER| the email receiver about bid email||
3835
|TC_URL| the base URL of topcoder to get the challenge URL| defaults to `https://www.topcoder-dev.com`|
3936
|GITLAB_API_BASE_URL| the URL for gitlab host| defaults to `https://gitlab.com`|
4037
|PAID_ISSUE_LABEL|the label name for paid, should be one of the label configured in topcoder x ui|'tcx_Paid'|
@@ -60,6 +57,7 @@ For using with SSL, the options should be as
6057
```
6158
{
6259
connectionString: '<server>',
60+
groupId: <groupid>,
6361
ssl: {
6462
cert: '<certificate>',
6563
key: '<key>'

config/default.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = {
1818
TOPIC: process.env.TOPIC || 'tc-x-events',
1919
KAFKA_OPTIONS: {
2020
connectionString: process.env.KAFKA_URL || 'localhost:9092',
21+
groupId: process.env.KAFKA_GROUP_ID || 'topcoder-x-processor',
2122
ssl: {
2223
cert: process.env.KAFKA_CLIENT_CERT || fs.readFileSync('./kafka_client.cer'), // eslint-disable-line no-sync
2324
key: process.env.KAFKA_CLIENT_CERT_KEY || fs.readFileSync('./kafka_client.key'), // eslint-disable-line no-sync
@@ -53,18 +54,6 @@ module.exports = {
5354
// NOTE: if subTrack is FIRST_2_FINISH,
5455
// this config has no effect since the ***EndsAt will be set automatically by TC APIs
5556
NEW_CHALLENGE_DURATION_IN_DAYS: process.env.NEW_CHALLENGE_DURATION_IN_DAYS || 5,
56-
// node mailer option
57-
NODE_MAILER_OPTIONS: {
58-
host: process.env.SMTP_HOST || process.env.MAILGUN_SMTP_SERVER || 'smtp.gmail.com',
59-
port: process.env.SMTP_PORT || process.env.MAILGUN_SMTP_POR || 465,
60-
secure: process.env.SMTP_IS_SECURE || true,
61-
auth: {
62-
user: process.env.SMTP_USERNAME || process.env.MAILGUN_SMTP_LOGIN || '',
63-
pass: process.env.SMTP_PASSWORD || process.env.MAILGUN_SMTP_PASSWORD || ''
64-
}
65-
},
66-
EMAIL_SENDER_ADDRESS: process.env.EMAIL_SENDER_ADDRESS || '',
67-
ISSUE_BID_EMAIL_RECEIVER: process.env.ISSUE_BID_EMAIL_RECEIVER || '',
6857
TC_URL: process.env.TC_URL || 'https://www.topcoder-dev.com',
6958
GITLAB_API_BASE_URL: process.env.GITLAB_API_BASE_URL || 'https://gitlab.com',
7059
PAID_ISSUE_LABEL: process.env.PAID_ISSUE_LABEL || 'tcx_Paid',

configuration.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ The following config parameters are supported, they are defined in `config/defau
99
|TOPIC | The Kafka topic where events are published. This must be the same as the configured value for topcoder-x-processor| |
1010
|KAFKA_OPTIONS | Kafka connection options| |
1111
|KAFKA_URL | The Kafka host to connect to| localhost:9092 |
12+
|KAFKA_GROUP_ID | The Kafka group id name| topcoder-x-processor |
1213
|KAFKA_CLIENT_CERT | The Kafka SSL certificate to use when connecting| Read from kafka_client.cer file, but this can be set as a string like it is on Heroku |
1314
|KAFKA_CLIENT_CERT_KEY | The Kafka SSL certificate key to use when connecting| Read from kafka_client.key file, but this can be set as a string like it is on Heroku|
1415
|TC_DEV_ENV| the flag whether to use topcoder development api or production| false|
1516
| NEW_CHALLENGE_TEMPLATE | the body template for new challenge request. You can change the subTrack, reviewTypes, technologies, .. here | see `default.js` |
1617
| NEW_CHALLENGE_DURATION_IN_DAYS | the duration of new challenge | 5 |
17-
| NODE_MAILER_OPTIONS| the node mailer smtp options, see [here](https://nodemailer.com/smtp/ for more detail)| see `default.js` |
18-
|EMAIL_SENDER_ADDRESS| the email sender email address||
19-
|ISSUE_BID_EMAIL_RECEIVER| the email receiver about bid email||
2018
|TC_URL| the base URL of topcoder to get the challenge URL| defaults to `https://www.topcoder-dev.com`|
2119
|GITLAB_API_BASE_URL| the URL for gitlab host| defaults to `https://gitlab.com`|
2220
|PAID_ISSUE_LABEL|the label name for paid, should be one of the label configured in topcoder x ui|'tcx_Paid'|

index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44
'use strict';
55

6+
const config = require('config');
7+
const _ = require('lodash');
68
const kafka = require('./utils/kafka');
79
const logger = require('./utils/logger');
810

@@ -19,5 +21,38 @@ process.on('unhandledRejection', (err) => {
1921
logger.logFullError(err, 'system');
2022
});
2123

24+
// dump the configuration to logger
25+
const ignoreConfigLog = ['cert', 'key', 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AUTH0_CLIENT_ID', 'AUTH0_CLIENT_SECRET'];
26+
/**
27+
* Print configs to logger
28+
* @param {Object} params the config params
29+
* @param {Number} level the level of param object
30+
*/
31+
function dumpConfigs(params, level) {
32+
Object.keys(params).forEach((key) => {
33+
if (_.includes(ignoreConfigLog, key)) {
34+
return;
35+
}
36+
const item = params[key];
37+
let str = '';
38+
let n = 0;
39+
while (n < level) { // eslint-disable-line no-restricted-syntax
40+
n++;
41+
str += ' ';
42+
}
43+
if (item && _.isObject(item)) {
44+
str += `${key}=`;
45+
logger.debug(str);
46+
dumpConfigs(item, level + 1);
47+
} else {
48+
str += `${key}=${item}`;
49+
logger.debug(str);
50+
}
51+
});
52+
}
53+
logger.debug('--- List of Configurations ---');
54+
dumpConfigs(config, 0);
55+
logger.debug('--- End of List of Configurations ---');
56+
2257
// run the server
2358
kafka.run();

services/EmailService.js

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

services/EventService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
const config = require('config');
1212
const _ = require('lodash');
1313
const logger = require('../utils/logger');
14-
const gitHubService = require('./GithubService');
15-
const gitlabService = require('./GitlabService');
1614
const models = require('../models');
1715
const dbHelper = require('../utils/db-helper');
16+
const gitHubService = require('./GithubService');
17+
const gitlabService = require('./GitlabService');
1818

1919
const timeoutMapper = {};
2020

services/IssueService.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const models = require('../models');
2121
const dbHelper = require('../utils/db-helper');
2222
const helper = require('../utils/helper');
2323
const gitHelper = require('../utils/git-helper');
24-
const emailService = require('./EmailService');
2524
const userService = require('./UserService');
2625
const eventService = require('./EventService');
2726

@@ -269,7 +268,6 @@ async function handleIssueComment(event, issue) {
269268
const parsedComment = parseComment(event.data.comment);
270269
if (parsedComment.isBid) {
271270
logger.debug(`New bid is received with amount ${parsedComment.bidAmount}.`);
272-
await emailService.sendNewBidEmail(event.data, parsedComment.bidAmount);
273271
}
274272
if (parsedComment.isAcceptBid) {
275273
logger.debug(`Bid by ${parsedComment.assignedUser} is accepted with amount ${parsedComment.bidAmount} `);

utils/kafka.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const logger = require('./logger');
2121

2222
class Kafka {
2323
constructor() {
24-
this.consumer = new kafka.SimpleConsumer(config.KAFKA_OPTIONS);
24+
this.consumer = new kafka.GroupConsumer(config.KAFKA_OPTIONS);
2525

2626
this.producer = new kafka.Producer(config.KAFKA_OPTIONS);
2727
this.producer.init().then(() => {
@@ -77,10 +77,12 @@ class Kafka {
7777
}
7878

7979
run() {
80-
this.consumer.init().then(() => {
80+
this.consumer.init([{
81+
subscriptions: [config.TOPIC],
82+
handler: this.messageHandler
83+
}]).then(() => {
8184
logger.info('kafka consumer is ready');
8285
healthcheck.init([this.check]);
83-
this.consumer.subscribe(config.TOPIC, {}, this.messageHandler);
8486
}).catch((err) => {
8587
logger.error(`kafka consumer is not connected. ${err.stack}`);
8688
});

0 commit comments

Comments
 (0)