Skip to content

Commit fd7dc32

Browse files
Merge pull request #272 from topcoder-platform/dev
[PROD] Next Release
2 parents 6149e5f + 93f136f commit fd7dc32

File tree

74 files changed

+30205
-11242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+30205
-11242
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ workflows:
6868
branches:
6969
only:
7070
- dev
71+
- change-validatations-in-job-jc
7172

7273
# Production builds are exectuted only on tagged commits to the
7374
# master branch.

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
tc-taas-es-processor | [2021-04-09T21:20:19.035Z] app INFO : Starting kafka consumer
8888
tc-taas-es-processor | 2021-04-09T21:20:21.292Z INFO no-kafka-client Joined group taas-es-processor generationId 1 as no-kafka-client-076538fc-60dd-4ca4-a2b9-520bdf73bc9e
8989
tc-taas-es-processor | 2021-04-09T21:20:21.293Z INFO no-kafka-client Elected as group leader
90+
tc-taas-es-processor | 2021-04-09T21:20:21.449Z DEBUG no-kafka-client Subscribed to taas.role.update:0 offset 0 leader kafka:9093
91+
tc-taas-es-processor | 2021-04-09T21:20:21.450Z DEBUG no-kafka-client Subscribed to taas.role.delete:0 offset 0 leader kafka:9093
92+
tc-taas-es-processor | 2021-04-09T21:20:21.451Z DEBUG no-kafka-client Subscribed to taas.role.requested:0 offset 0 leader kafka:9093
9093
tc-taas-es-processor | 2021-04-09T21:20:21.452Z DEBUG no-kafka-client Subscribed to taas.jobcandidate.create:0 offset 0 leader kafka:9093
9194
tc-taas-es-processor | 2021-04-09T21:20:21.455Z DEBUG no-kafka-client Subscribed to taas.job.create:0 offset 0 leader kafka:9093
9295
tc-taas-es-processor | 2021-04-09T21:20:21.456Z DEBUG no-kafka-client Subscribed to taas.resourcebooking.delete:0 offset 0 leader kafka:9093
@@ -100,10 +103,11 @@
100103
tc-taas-es-processor | 2021-04-09T21:20:21.469Z DEBUG no-kafka-client Subscribed to taas.workperiodpayment.update:0 offset 0 leader kafka:9093
101104
tc-taas-es-processor | 2021-04-09T21:20:21.470Z DEBUG no-kafka-client Subscribed to taas.workperiodpayment.delete:0 offset 0 leader kafka:9093
102105
tc-taas-es-processor | 2021-04-09T21:20:21.471Z DEBUG no-kafka-client Subscribed to taas.workperiodpayment.create:0 offset 0 leader kafka:9093
106+
tc-taas-es-processor | 2021-04-09T21:20:21.472Z DEBUG no-kafka-client Subscribed to taas.action.retry:0 offset 0 leader kafka:9093
103107
tc-taas-es-processor | 2021-04-09T21:20:21.473Z DEBUG no-kafka-client Subscribed to taas.job.update:0 offset 0 leader kafka:9093
104108
tc-taas-es-processor | 2021-04-09T21:20:21.474Z DEBUG no-kafka-client Subscribed to taas.resourcebooking.update:0 offset 0 leader kafka:9093
105109
tc-taas-es-processor | [2021-04-09T21:20:21.475Z] app INFO : Initialized.......
106-
tc-taas-es-processor | [2021-04-09T21:20:21.479Z] app INFO : taas.job.create,taas.job.update,taas.job.delete,taas.jobcandidate.create,taas.jobcandidate.update,taas.jobcandidate.delete,taas.resourcebooking.create,taas.resourcebooking.update,taas.resourcebooking.delete,taas.workperiod.create,taas.workperiod.update,taas.workperiod.delete,taas.workperiodpayment.create,taas.workperiodpayment.update,taas.workperiodpayment.delete
110+
tc-taas-es-processor | [2021-04-09T21:20:21.479Z] app INFO : common.error.reporting,taas.job.create,taas.job.update,taas.job.delete,taas.jobcandidate.create,taas.jobcandidate.update,taas.jobcandidate.delete,taas.resourcebooking.create,taas.resourcebooking.update,taas.resourcebooking.delete,taas.workperiod.create,taas.workperiod.update,taas.workperiod.delete,taas.workperiodpayment.create,taas.workperiodpayment.update,taas.interview.requested,taas.interview.update,taas.interview.bulkUpdate,taas.role.requested,taas.role.update,taas.role.delete,taas.action.retry
107111
tc-taas-es-processor | [2021-04-09T21:20:21.480Z] app INFO : Kick Start.......
108112
tc-taas-es-processor | ********** Topcoder Health Check DropIn listening on port 3001
109113
tc-taas-es-processor | Topcoder Health Check DropIn started and ready to roll
@@ -173,6 +177,19 @@ To be able to change and test `taas-es-processor` locally you can follow the nex
173177
2. Run `taas-es-processor` separately from the source code. As `npm run services:up` already run all the dependencies for both `taas-apis` and for `taas-es-processor`. The only thing you need to do for running `taas-es-processor` locally is clone the [taas-es-processor](https://github.com/topcoder-platform/taas-es-processor) repository and inside `taas-es-processor` folder run:
174178
- `nvm use` - to use correct Node version
175179
- `npm run install`
180+
- Create `.env` file with the next environment variables. Values for **Auth0 config** should be shared with you on the forum.<br>
181+
182+
```bash
183+
# Auth0 config
184+
AUTH0_URL=
185+
AUTH0_AUDIENCE=
186+
AUTH0_CLIENT_ID=
187+
AUTH0_CLIENT_SECRET=
188+
```
189+
190+
- Values from this file would be automatically used by many `npm` commands.
191+
- ⚠️ Never commit this file or its copy to the repository!
192+
176193
- `npm run start`
177194

178195
## NPM Commands
@@ -194,7 +211,7 @@ To be able to change and test `taas-es-processor` locally you can follow the nex
194211
| `npm run index:jobs <jobId>` | Indexes job data from db into ES, if jobId is not given all data is indexed. Use `-- --force` flag to skip confirmation |
195212
| `npm run index:job-candidates <jobCandidateId>` | Indexes job candidate data from db into ES, if jobCandidateId is not given all data is indexed. Use `-- --force` flag to skip confirmation |
196213
| `npm run index:resource-bookings <resourceBookingsId>` | Indexes resource bookings data from db into ES, if resourceBookingsId is not given all data is indexed. Use `-- --force` flag to skip confirmation |
197-
| `npm run index:work-periods <workPeriodId>` | Indexes work periods data from db into ES, if workPeriodId is not given all data is indexed. Use `-- --force` flag to skip confirmation |
214+
| `npm run index:roles <roleId>` | Indexes roles data from db into ES, if roleId is not given all data is indexed. Use `-- --force` flag to skip confirmation |
198215
| `npm run services:up` | Start services via docker-compose for local development. |
199216
| `npm run services:down` | Stop services via docker-compose for local development. |
200217
| `npm run services:logs -- -f <service_name>` | View logs of some service inside docker-compose. |
@@ -203,6 +220,7 @@ To be able to change and test `taas-es-processor` locally you can follow the nex
203220
| `npm run cov` | Code Coverage Report. |
204221
| `npm run migrate` | Run any migration files which haven't run yet. |
205222
| `npm run migrate:undo` | Revert most recent migration. |
223+
| `npm run demo-payment-scheduler` | Create 1000 Work Periods Payment records in with status "scheduled" and various "amount" |
206224
207225
## Import and Export data
208226

app-constants.js

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const Scopes = {
3434
ALL_RESOURCE_BOOKING: 'all:taas-resourceBookings',
3535
// taas-team
3636
READ_TAAS_TEAM: 'read:taas-teams',
37+
CREATE_ROLE_SEARCH_REQUEST: 'create:taas-roleSearchRequests',
38+
CREATE_TAAS_TEAM: 'create:taas-teams',
3739
// work period
3840
READ_WORK_PERIOD: 'read:taas-workPeriods',
3941
CREATE_WORK_PERIOD: 'create:taas-workPeriods',
@@ -49,7 +51,13 @@ const Scopes = {
4951
READ_INTERVIEW: 'read:taas-interviews',
5052
CREATE_INTERVIEW: 'create:taas-interviews',
5153
UPDATE_INTERVIEW: 'update:taas-interviews',
52-
ALL_INTERVIEW: 'all:taas-interviews'
54+
ALL_INTERVIEW: 'all:taas-interviews',
55+
// role
56+
READ_ROLE: 'read:taas-roles',
57+
CREATE_ROLE: 'create:taas-roles',
58+
UPDATE_ROLE: 'update:taas-roles',
59+
DELETE_ROLE: 'delete:taas-roles',
60+
ALL_ROLE: 'all:taas-roles'
5361
}
5462

5563
// Interview related constants
@@ -76,16 +84,85 @@ const ChallengeStatus = {
7684
COMPLETED: 'Completed'
7785
}
7886

87+
/**
88+
* Aggregate payment status for Work Period which is determined
89+
* based on the payments the Work Period has using `PaymentStatusRules`
90+
*/
91+
const AggregatePaymentStatus = {
92+
PENDING: 'pending',
93+
IN_PROGRESS: 'in-progress',
94+
PARTIALLY_COMPLETED: 'partially-completed',
95+
COMPLETED: 'completed',
96+
NO_DAYS: 'no-days'
97+
}
98+
99+
/**
100+
* `WorkPeriodPayment.status` - possible values
101+
*/
102+
const WorkPeriodPaymentStatus = {
103+
COMPLETED: 'completed',
104+
SCHEDULED: 'scheduled',
105+
IN_PROGRESS: 'in-progress',
106+
FAILED: 'failed',
107+
CANCELLED: 'cancelled'
108+
}
109+
110+
/**
111+
* The rules how to determine WorkPeriod.paymentStatus based on the payments
112+
*
113+
* The top rule has priority over the bottom rules.
114+
*/
115+
const PaymentStatusRules = [
116+
{ paymentStatus: AggregatePaymentStatus.NO_DAYS, condition: { daysWorked: 0 } },
117+
{ paymentStatus: AggregatePaymentStatus.IN_PROGRESS, condition: { hasWorkPeriodPaymentStatus: [WorkPeriodPaymentStatus.SCHEDULED, WorkPeriodPaymentStatus.IN_PROGRESS] } },
118+
{ paymentStatus: AggregatePaymentStatus.COMPLETED, condition: { hasWorkPeriodPaymentStatus: [WorkPeriodPaymentStatus.COMPLETED], hasDueDays: false } },
119+
{ paymentStatus: AggregatePaymentStatus.PARTIALLY_COMPLETED, condition: { hasWorkPeriodPaymentStatus: [WorkPeriodPaymentStatus.COMPLETED], hasDueDays: true } },
120+
{ paymentStatus: AggregatePaymentStatus.PENDING, condition: { hasDueDays: true } }
121+
]
122+
123+
/**
124+
* The WorkPeriodPayment.status values which we take into account when calculate
125+
* aggregate values inside WorkPeriod:
126+
* - daysPaid
127+
* - paymentTotal
128+
* - paymentStatus
129+
*/
130+
const ActiveWorkPeriodPaymentStatuses = [
131+
WorkPeriodPaymentStatus.SCHEDULED,
132+
WorkPeriodPaymentStatus.IN_PROGRESS,
133+
WorkPeriodPaymentStatus.COMPLETED
134+
]
135+
136+
const WorkPeriodPaymentUpdateStatus = {
137+
SCHEDULED: 'scheduled',
138+
CANCELLED: 'cancelled'
139+
}
140+
79141
const PaymentProcessingSwitch = {
80142
ON: 'ON',
81143
OFF: 'OFF'
82144
}
83145

146+
const PaymentSchedulerStatus = {
147+
START_PROCESS: 'start-process',
148+
CREATE_CHALLENGE: 'create-challenge',
149+
ASSIGN_MEMBER: 'assign-member',
150+
ACTIVATE_CHALLENGE: 'activate-challenge',
151+
GET_USER_ID: 'get-userId',
152+
CLOSE_CHALLENGE: 'close-challenge'
153+
}
154+
84155
module.exports = {
85156
UserRoles,
86157
FullManagePermissionRoles,
87158
Scopes,
88159
Interviews,
89160
ChallengeStatus,
90-
PaymentProcessingSwitch
161+
AggregatePaymentStatus,
162+
WorkPeriodPaymentStatus,
163+
WorkPeriodPaymentUpdateStatus,
164+
PaymentSchedulerStatus,
165+
PaymentProcessingSwitch,
166+
PaymentStatusRules,
167+
ActiveWorkPeriodPaymentStatuses
91168
}

app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const schedule = require('node-schedule')
1313
const logger = require('./src/common/logger')
1414
const eventHandlers = require('./src/eventHandlers')
1515
const interviewService = require('./src/services/InterviewService')
16+
const { processScheduler } = require('./src/services/PaymentSchedulerService')
1617

1718
// setup express app
1819
const app = express()
@@ -97,6 +98,9 @@ const server = app.listen(app.get('port'), () => {
9798
eventHandlers.init()
9899
// schedule updateCompletedInterviews to run every hour
99100
schedule.scheduleJob('0 0 * * * *', interviewService.updateCompletedInterviews)
101+
102+
// schedule payment processing
103+
schedule.scheduleJob(config.PAYMENT_PROCESSING.CRON, processScheduler)
100104
})
101105

102106
if (process.env.NODE_ENV === 'test') {

config/default.js

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = {
4040

4141
TOPCODER_USERS_API: process.env.TOPCODER_USERS_API || 'https://api.topcoder-dev.com/v3/users',
4242
// the api to find topcoder members
43-
TOPCODER_MEMBERS_API: process.env.TOPCODER_MEMBERS_API || 'https://api.topcoder-dev.com/v3/members',
43+
TOPCODER_MEMBERS_API: process.env.TOPCODER_MEMBERS_API || 'https://api.topcoder-dev.com/v5/members',
4444
// rate limit of requests to user api
4545
MAX_PARALLEL_REQUEST_TOPCODER_USERS_API: process.env.MAX_PARALLEL_REQUEST_TOPCODER_USERS_API || 100,
4646

@@ -76,8 +76,8 @@ module.exports = {
7676
ES_INDEX_JOB_CANDIDATE: process.env.ES_INDEX_JOB_CANDIDATE || 'job_candidate',
7777
// the resource booking index
7878
ES_INDEX_RESOURCE_BOOKING: process.env.ES_INDEX_RESOURCE_BOOKING || 'resource_booking',
79-
// the work period index
80-
ES_INDEX_WORK_PERIOD: process.env.ES_INDEX_WORK_PERIOD || 'work_period',
79+
// the role index
80+
ES_INDEX_ROLE: process.env.ES_INDEX_ROLE || 'role',
8181

8282
// the max bulk size in MB for ES indexing
8383
MAX_BULK_REQUEST_SIZE_MB: process.env.MAX_BULK_REQUEST_SIZE_MB || 20,
@@ -133,6 +133,15 @@ module.exports = {
133133
TAAS_INTERVIEW_UPDATE_TOPIC: process.env.TAAS_INTERVIEW_UPDATE_TOPIC || 'taas.interview.update',
134134
// the interview bulk update Kafka message topic
135135
TAAS_INTERVIEW_BULK_UPDATE_TOPIC: process.env.TAAS_INTERVIEW_BULK_UPDATE_TOPIC || 'taas.interview.bulkUpdate',
136+
// topics for role service
137+
// the create role entity Kafka message topic
138+
TAAS_ROLE_CREATE_TOPIC: process.env.TAAS_ROLE_CREATE_TOPIC || 'taas.role.requested',
139+
// the update role entity Kafka message topic
140+
TAAS_ROLE_UPDATE_TOPIC: process.env.TAAS_ROLE_UPDATE_TOPIC || 'taas.role.update',
141+
// the delete role entity Kafka message topic
142+
TAAS_ROLE_DELETE_TOPIC: process.env.TAAS_ROLE_DELETE_TOPIC || 'taas.role.delete',
143+
// special kafka topics
144+
TAAS_ACTION_RETRY_TOPIC: process.env.TAAS_ACTION_RETRY_TOPIC || 'taas.action.retry',
136145

137146
// the Kafka message topic for sending email
138147
EMAIL_TOPIC: process.env.EMAIL_TOPIC || 'external.action.email',
@@ -163,6 +172,45 @@ module.exports = {
163172
TYPE_ID_TASK: process.env.TYPE_ID_TASK || 'ecd58c69-238f-43a4-a4bb-d172719b9f31',
164173
DEFAULT_TIMELINE_TEMPLATE_ID: process.env.DEFAULT_TIMELINE_TEMPLATE_ID || '53a307ce-b4b3-4d6f-b9a1-3741a58f77e6',
165174
DEFAULT_TRACK_ID: process.env.DEFAULT_TRACK_ID || '9b6fc876-f4d9-4ccb-9dfd-419247628825',
166-
167-
PAYMENT_PROCESSING_SWITCH: process.env.PAYMENT_PROCESSING_SWITCH || 'OFF'
175+
// the minimum matching rate when searching roles by skills
176+
ROLE_MATCHING_RATE: process.env.ROLE_MATCHING_RATE || 0.70,
177+
// member groups representing Wipro or TopCoder employee
178+
INTERNAL_MEMBER_GROUPS: process.env.INTERNAL_MEMBER_GROUPS || ['20000000', '20000001', '20000003', '20000010', '20000015'],
179+
// Topcoder skills cache time in minutes
180+
TOPCODER_SKILLS_CACHE_TIME: process.env.TOPCODER_SKILLS_CACHE_TIME || 60,
181+
// payment scheduler config
182+
PAYMENT_PROCESSING: {
183+
// switch off actual API calls in Payment Scheduler
184+
SWITCH: process.env.PAYMENT_PROCESSING_SWITCH || 'OFF',
185+
// the payment scheduler cron config
186+
CRON: process.env.PAYMENT_PROCESSING_CRON || '0 */5 * * * *',
187+
// the number of records processed by one time
188+
BATCH_SIZE: parseInt(process.env.PAYMENT_PROCESSING_BATCH_SIZE || 50),
189+
// in-progress expired to determine whether a record has been processed abnormally, moment duration format
190+
IN_PROGRESS_EXPIRED: process.env.IN_PROGRESS_EXPIRED || 'PT1H',
191+
// the number of max retry config
192+
MAX_RETRY_COUNT: parseInt(process.env.PAYMENT_PROCESSING_MAX_RETRY_COUNT || 10),
193+
// the time of retry base delay, unit: ms
194+
RETRY_BASE_DELAY: parseInt(process.env.PAYMENT_PROCESSING_RETRY_BASE_DELAY || 100),
195+
// the time of retry max delay, unit: ms
196+
RETRY_MAX_DELAY: parseInt(process.env.PAYMENT_PROCESSING_RETRY_MAX_DELAY || 10000),
197+
// the max time of one request, unit: ms
198+
PER_REQUEST_MAX_TIME: parseInt(process.env.PAYMENT_PROCESSING_PER_REQUEST_MAX_TIME || 30000),
199+
// the max time of one payment record, unit: ms
200+
PER_PAYMENT_MAX_TIME: parseInt(process.env.PAYMENT_PROCESSING_PER_PAYMENT_MAX_TIME || 60000),
201+
// the max records of payment of a minute
202+
PER_MINUTE_PAYMENT_MAX_COUNT: parseInt(process.env.PAYMENT_PROCESSING_PER_MINUTE_PAYMENT_MAX_COUNT || 12),
203+
// the max requests of challenge of a minute
204+
PER_MINUTE_CHALLENGE_REQUEST_MAX_COUNT: parseInt(process.env.PAYMENT_PROCESSING_PER_MINUTE_CHALLENGE_REQUEST_MAX_COUNT || 60),
205+
// the max requests of resource of a minute
206+
PER_MINUTE_RESOURCE_REQUEST_MAX_COUNT: parseInt(process.env.PAYMENT_PROCESSING_PER_MINUTE_CHALLENGE_REQUEST_MAX_COUNT || 20),
207+
// the default step fix delay, unit: ms
208+
FIX_DELAY_STEP: parseInt(process.env.PAYMENT_PROCESSING_FIX_DELAY_STEP || 500),
209+
// the fix delay after step of create challenge, unit: ms
210+
FIX_DELAY_STEP_CREATE_CHALLENGE: parseInt(process.env.PAYMENT_PROCESSING_FIX_DELAY_STEP_CREATE_CHALLENGE || process.env.PAYMENT_PROCESSING_FIX_DELAY_STEP || 500),
211+
// the fix delay after step of assign member, unit: ms
212+
FIX_DELAY_STEP_ASSIGN_MEMBER: parseInt(process.env.PAYMENT_PROCESSING_FIX_DELAY_STEP_ASSIGN_MEMBER || process.env.PAYMENT_PROCESSING_FIX_DELAY_STEP || 500),
213+
// the fix delay after step of activate challenge, unit: ms
214+
FIX_DELAY_STEP_ACTIVATE_CHALLENGE: parseInt(process.env.PAYMENT_PROCESSING_FIX_DELAY_STEP_ACTIVATE_CHALLENGE || process.env.PAYMENT_PROCESSING_FIX_DELAY_STEP || 500)
215+
}
168216
}

0 commit comments

Comments
 (0)