Skip to content

Commit 3538258

Browse files
authored
Merge pull request #69 from eisbilir/feature/new-action-topic
action topic and service added
2 parents 1b8e22d + 3716995 commit 3538258

File tree

10 files changed

+365
-32
lines changed

10 files changed

+365
-32
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ The following parameters can be set in config files or in env variables:
2020
- `KAFKA_CLIENT_CERT_KEY`: Kafka connection private key, optional;
2121
if not provided, then SSL connection is not used, direct insecure connection is used;
2222
if provided, it can be either path to private key file or private key content
23+
- `KAFKA_MESSAGE_ORIGINATOR`: The originator value for the kafka messages
2324
- `KAFKA_GROUP_ID`: the Kafka group id
25+
- `topics.KAFKA_ERROR_TOPIC`: the error topic at which bus api will publish any errors
2426
- `topics.TAAS_JOB_CREATE_TOPIC`: the create job entity Kafka message topic
2527
- `topics.TAAS_JOB_UPDATE_TOPIC`: the update job entity Kafka message topic
2628
- `topics.TAAS_JOB_DELETE_TOPIC`: the delete job entity Kafka message topic
@@ -41,6 +43,10 @@ The following parameters can be set in config files or in env variables:
4143
- `topics.TAAS_ROLE_CREATE_TOPIC`: the create role entity Kafka message topic
4244
- `topics.TAAS_ROLE_UPDATE_TOPIC`: the update role entity Kafka message topic
4345
- `topics.TAAS_ROLE_DELETE_TOPIC`: the delete role entity Kafka message topic
46+
- `topics.TAAS_ACTION_RETRY_TOPIC`: the retry process Kafka message topic
47+
- `MAX_RETRY`: maximum allowed retry count for failed operations for sending `taas.action.retry` message
48+
- `BASE_RETRY_DELAY`: base amount of retry delay (ms) for failed operations
49+
- `BUSAPI_URL`: Topcoder Bus API URL
4450
- `esConfig.HOST`: Elasticsearch host
4551
- `esConfig.AWS_REGION`: The Amazon region to use when using AWS Elasticsearch service
4652
- `esConfig.ELASTICCLOUD.id`: The elastic cloud id, if your elasticsearch instance is hosted on elastic cloud. DO NOT provide a value for ES_HOST if you are using this
@@ -56,6 +62,7 @@ The following parameters can be set in config files or in env variables:
5662
- `auth0.AUTH0_CLIENT_ID`: Auth0 client id, used to get TC M2M token
5763
- `auth0.AUTH0_CLIENT_SECRET`: Auth0 client secret, used to get TC M2M token
5864
- `auth0.AUTH0_PROXY_SERVER_URL`: Proxy Auth0 URL, used to get TC M2M token
65+
- `auth0.TOKEN_CACHE_TIME`: Auth0 token cache time, used to get TC M2M token
5966

6067
- `zapier.ZAPIER_COMPANYID_SLUG`: your company id in zapier; numeric value
6168
- `zapier.ZAPIER_CONTACTID_SLUG`: your contact id in zapier; numeric value

config/default.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* The default configuration file.
33
*/
4-
4+
require('dotenv').config()
55
module.exports = {
66
PORT: process.env.PORT || 3001,
77
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
@@ -14,8 +14,12 @@ module.exports = {
1414

1515
// Kafka group id
1616
KAFKA_GROUP_ID: process.env.KAFKA_GROUP_ID || 'taas-es-processor',
17+
// The originator value for the kafka messages
18+
KAFKA_MESSAGE_ORIGINATOR: process.env.KAFKA_MESSAGE_ORIGINATOR || 'taas-es-processor',
1719

1820
topics: {
21+
// The error topic at which bus api will publish any errors
22+
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'common.error.reporting',
1923
// topics for job service
2024
TAAS_JOB_CREATE_TOPIC: process.env.TAAS_JOB_CREATE_TOPIC || 'taas.job.create',
2125
TAAS_JOB_UPDATE_TOPIC: process.env.TAAS_JOB_UPDATE_TOPIC || 'taas.job.update',
@@ -42,8 +46,17 @@ module.exports = {
4246
// topics for role service
4347
TAAS_ROLE_CREATE_TOPIC: process.env.TAAS_ROLE_CREATE_TOPIC || 'taas.role.requested',
4448
TAAS_ROLE_UPDATE_TOPIC: process.env.TAAS_ROLE_UPDATE_TOPIC || 'taas.role.update',
45-
TAAS_ROLE_DELETE_TOPIC: process.env.TAAS_ROLE_DELETE_TOPIC || 'taas.role.delete'
49+
TAAS_ROLE_DELETE_TOPIC: process.env.TAAS_ROLE_DELETE_TOPIC || 'taas.role.delete',
50+
// special kafka topics
51+
TAAS_ACTION_RETRY_TOPIC: process.env.TAAS_ACTION_RETRY_TOPIC || 'taas.action.retry'
52+
4653
},
54+
// maximum allowed retry count for failed operations for sending `action.retry` message
55+
MAX_RETRY: process.env.MAX_RETRY || 3,
56+
// base amount of retry delay for failed operations
57+
BASE_RETRY_DELAY: process.env.BASE_RETRY_DELAY || 500,
58+
// Topcoder Bus API URL
59+
BUSAPI_URL: process.env.BUSAPI_URL || 'https://api.topcoder-dev.com/v5',
4760

4861
esConfig: {
4962
HOST: process.env.ES_HOST || 'http://localhost:9200',
@@ -67,7 +80,8 @@ module.exports = {
6780
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,
6881
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
6982
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
70-
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL
83+
AUTH0_PROXY_SERVER_URL: process.env.AUTH0_PROXY_SERVER_URL,
84+
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME
7185
},
7286

7387
zapier: {

package-lock.json

Lines changed: 126 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
"dependencies": {
3535
"@elastic/elasticsearch": "^7.9.1",
3636
"@hapi/joi": "^15.1.0",
37+
"@topcoder-platform/topcoder-bus-api-wrapper": "github:topcoder-platform/tc-bus-api-wrapper",
3738
"async-mutex": "^0.2.4",
3839
"aws-sdk": "^2.476.0",
3940
"bluebird": "^3.5.5",
4041
"config": "^3.1.0",
42+
"dotenv": "^10.0.0",
4143
"get-parameter-names": "^0.3.0",
4244
"lodash": "^4.17.20",
4345
"no-kafka": "^3.4.3",

src/app.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ const WorkPeriodProcessorService = require('./services/WorkPeriodProcessorServic
1616
const InterviewProcessorService = require('./services/InterviewProcessorService')
1717
const WorkPeriodPaymentProcessorService = require('./services/WorkPeriodPaymentProcessorService')
1818
const RoleProcessorService = require('./services/RoleProcessorService')
19+
const ActionProcessorService = require('./services/ActionProcessorService')
1920
const Mutex = require('async-mutex').Mutex
2021
const events = require('events')
2122

2223
const eventEmitter = new events.EventEmitter()
2324

2425
// healthcheck listening port
2526
process.env.PORT = config.PORT
26-
2727
const localLogger = {
2828
info: (message) => logger.info({ component: 'app', message }),
2929
debug: (message) => logger.debug({ component: 'app', message }),
@@ -57,7 +57,9 @@ const topicServiceMapping = {
5757
// role
5858
[config.topics.TAAS_ROLE_CREATE_TOPIC]: RoleProcessorService.processCreate,
5959
[config.topics.TAAS_ROLE_UPDATE_TOPIC]: RoleProcessorService.processUpdate,
60-
[config.topics.TAAS_ROLE_DELETE_TOPIC]: RoleProcessorService.processDelete
60+
[config.topics.TAAS_ROLE_DELETE_TOPIC]: RoleProcessorService.processDelete,
61+
// action
62+
[config.topics.TAAS_ACTION_RETRY_TOPIC]: ActionProcessorService.processRetry
6163
}
6264

6365
// Start kafka consumer
@@ -179,5 +181,6 @@ if (!module.parent) {
179181

180182
module.exports = {
181183
initConsumer,
182-
eventEmitter
184+
eventEmitter,
185+
topicServiceMapping
183186
}

src/common/errors.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* This file defines application errors
3+
*/
4+
const util = require('util')
5+
6+
/**
7+
* Helper function to create generic error object with http status code
8+
* @param {String} name the error name
9+
* @param {Number} statusCode the http status code
10+
* @returns {Function} the error constructor
11+
* @private
12+
*/
13+
function createError (name, statusCode) {
14+
/**
15+
* The error constructor
16+
* @param {String} message the error message
17+
* @param {String} [cause] the error cause
18+
* @constructor
19+
*/
20+
function ErrorCtor (message, cause) {
21+
Error.call(this)
22+
Error.captureStackTrace(this)
23+
this.message = message || name
24+
this.cause = cause
25+
this.httpStatus = statusCode
26+
}
27+
28+
util.inherits(ErrorCtor, Error)
29+
ErrorCtor.prototype.name = name
30+
return ErrorCtor
31+
}
32+
33+
module.exports = {
34+
BadRequestError: createError('BadRequestError', 400),
35+
UnauthorizedError: createError('UnauthorizedError', 401),
36+
ForbiddenError: createError('ForbiddenError', 403),
37+
NotFoundError: createError('NotFoundError', 404),
38+
ConflictError: createError('ConflictError', 409),
39+
InternalServerError: createError('InternalServerError', 500)
40+
}

0 commit comments

Comments
 (0)