Skip to content

Commit 01a2e08

Browse files
authored
Merge branch 'dev' into change-validatations-in-job-jc
2 parents 9a26840 + 99f4574 commit 01a2e08

40 files changed

+8938
-8429
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ install_dependency: &install_dependency
1111
install_deploysuite: &install_deploysuite
1212
name: Installation of install_deploysuite.
1313
command: |
14-
git clone --branch v1.4.2 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
14+
git clone --branch v1.4.6 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
1515
cp ./../buildscript/master_deploy.sh .
1616
cp ./../buildscript/buildenv.sh .
1717
cp ./../buildscript/awsconfiguration.sh .

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,19 @@ To be able to change and test `taas-es-processor` locally you can follow the nex
177177
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:
178178
- `nvm use` - to use correct Node version
179179
- `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+
180193
- `npm run start`
181194

182195
## NPM Commands
@@ -207,6 +220,7 @@ To be able to change and test `taas-es-processor` locally you can follow the nex
207220
| `npm run cov` | Code Coverage Report. |
208221
| `npm run migrate` | Run any migration files which haven't run yet. |
209222
| `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" |
210224
211225
## Import and Export data
212226

app-constants.js

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,72 @@ const ChallengeStatus = {
8484
COMPLETED: 'Completed'
8585
}
8686

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+
*/
87102
const WorkPeriodPaymentStatus = {
88103
COMPLETED: 'completed',
89-
CANCELLED: 'cancelled',
90-
SCHEDULED: 'scheduled'
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+
141+
const PaymentProcessingSwitch = {
142+
ON: 'ON',
143+
OFF: 'OFF'
144+
}
145+
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'
91153
}
92154

93155
module.exports = {
@@ -96,5 +158,11 @@ module.exports = {
96158
Scopes,
97159
Interviews,
98160
ChallengeStatus,
99-
WorkPeriodPaymentStatus
161+
AggregatePaymentStatus,
162+
WorkPeriodPaymentStatus,
163+
WorkPeriodPaymentUpdateStatus,
164+
PaymentSchedulerStatus,
165+
PaymentProcessingSwitch,
166+
PaymentStatusRules,
167+
ActiveWorkPeriodPaymentStatuses
100168
}

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: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,42 @@ module.exports = {
175175
// the minimum matching rate when searching roles by skills
176176
ROLE_MATCHING_RATE: process.env.ROLE_MATCHING_RATE || 0.70,
177177
// member groups representing Wipro or TopCoder employee
178-
INTERNAL_MEMBER_GROUPS: process.env.INTERNAL_MEMBER_GROUPS || ['20000000', '20000001', '20000003', '20000010', '20000015']
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+
}
179216
}

0 commit comments

Comments
 (0)