Skip to content

Commit 578d9d6

Browse files
Merge pull request #451 from topcoder-platform/migrate-jobcandidates-scripts
Update Migrate jobcandidates scripts III
2 parents 4b2e814 + 8876cbb commit 578d9d6

File tree

4 files changed

+55
-31
lines changed

4 files changed

+55
-31
lines changed

config/default.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ module.exports = {
189189
SURVEY_COLLECTOR_PREFIX: process.env.WEEKLY_SURVEY_SURVEY_COLLECTOR_PREFIX || 'Week ending',
190190
SURVEY_MASTER_COLLECTOR_ID: process.env.WEEKLY_SURVEY_SURVEY_MASTER_COLLECTOR_ID || '',
191191
SURVEY_MASTER_MESSAGE_ID: process.env.WEEKLY_SURVEY_SURVEY_MASTER_MESSAGE_ID || '',
192-
SURVEY_CONTACT_GROUP_ID: process.env.WEEKLY_SURVEY_SURVEY_CONTACT_GROUP_ID || '',
192+
SURVEY_CONTACT_GROUP_ID: process.env.WEEKLY_SURVEY_SURVEY_CONTACT_GROUP_ID || ''
193193
},
194194
// payment scheduler config
195195
PAYMENT_PROCESSING: {

scripts/withdrawn-migration/backup.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ const currentStep = 'Backup'
1313
async function backup () {
1414
logger.info({ component: currentStep, message: '*************************** Backup process started ***************************' })
1515
const filePath = path.join(__dirname, '/temp/')
16+
if (fs.existsSync(filePath)) {
17+
fs.rmdirSync(filePath, { recursive: true })
18+
}
19+
fs.mkdirSync(filePath)
1620
const Op = Sequelize.Op
1721
const jobCandidates = await JobCandidate.findAll({
1822
where: {
1923
status: 'placed'
2024
}
2125
})
22-
26+
let summary = 0
2327
for (let i = 0; i < jobCandidates.length; i++) {
2428
const jc = jobCandidates[i]
2529
let job = null
@@ -56,12 +60,12 @@ async function backup () {
5660
where: filter
5761
})
5862
if (candidates && candidates.length > 0) {
59-
fs.writeFile(filePath + 'jobcandidate-backup.json', JSON.stringify(
63+
summary += candidates.length
64+
fs.writeFile(filePath + `jobcandidate-backup-${i+1}.json`, JSON.stringify(
6065
candidates
6166
), (err) => {
6267
if (!err) {
63-
logger.info({ component: `${currentStep} Summary`, message: `Backup up finished. There are ${candidates.length} jobCandidates that need to be updated` })
64-
logger.info({ component: currentStep, message: '*************************** Backup process finished ***************************' })
68+
logger.info({ component: `${currentStep} Sub`, message: `There are ${candidates.length} jobCandidates that need to be updated for userId: ${jc.userId}` })
6569
return
6670
}
6771
logger.error({ component: currentStep, message: err.message })
@@ -70,6 +74,8 @@ async function backup () {
7074
}
7175
}
7276
}
77+
logger.info({ component: `${currentStep}`, message: `Report: there are ${summary} jobCandidates in total` })
78+
logger.info({ component: currentStep, message: '*************************** Backup process finished ***************************' })
7379
}
7480

7581
backup().then(() => {

scripts/withdrawn-migration/migration.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,28 @@ const currentStep = 'Migration'
1212
async function migration () {
1313
logger.info({ component: currentStep, message: '*************************** Migration process started ***************************' })
1414
const filePath = path.join(__dirname, '/temp/')
15-
const data = fs.readFileSync(filePath + 'jobCandidate-backup.json', 'utf-8')
16-
const jobCandidates = JSON.parse(data)
17-
let summary = 0
18-
for (var i = 0; i < jobCandidates.length; i++) {
19-
const jc = await JobCandidate.findById(jobCandidates[i].id)
20-
if (jc) {
21-
const oldStatus = jc.status
22-
const updated = await jc.update({ status: config.WITHDRAWN_STATUS_CHANGE_MAPPING[jobCandidates[i].status] })
23-
summary++
24-
logger.info({ component: currentStep, message: `jobCandidate with ${jc.id} status changed from ${oldStatus} to ${updated.status}` })
25-
}
26-
};
27-
logger.info({ component: currentStep, message: `Totally updated ${summary} jobCandidates` })
15+
const files = []
16+
fs.readdirSync(filePath).forEach(async (file) => {
17+
files.push(`${filePath}${file}`)
18+
})
19+
let totalSum = 0
20+
for (let j = 0; j < files.length; j++) {
21+
const data = fs.readFileSync(files[j], 'utf-8')
22+
const jobCandidates = JSON.parse(data)
23+
let summary = 0
24+
for (let i = 0; i < jobCandidates.length; i++) {
25+
const jc = await JobCandidate.findById(jobCandidates[i].id)
26+
if (jc) {
27+
const oldStatus = jc.status
28+
const updated = await jc.update({ status: config.WITHDRAWN_STATUS_CHANGE_MAPPING[jobCandidates[i].status] })
29+
summary++
30+
totalSum++
31+
logger.info({ component: currentStep, message: `jobCandidate with ${jc.id} status changed from ${oldStatus} to ${updated.status}` })
32+
}
33+
};
34+
logger.info({ component: `${currentStep} Sub`, message: `Updated ${summary} jobCandidates from ${files[j]}` })
35+
}
36+
logger.info({ component: currentStep, message: `Report: Totally Updated ${totalSum} jobCandidates` })
2837
logger.info({ component: currentStep, message: '*************************** Migration process finished ***************************' })
2938
}
3039

scripts/withdrawn-migration/restore.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,28 @@ const currentStep = 'Restore'
1111
async function restore () {
1212
logger.info({ component: currentStep, message: '*************************** Restore process started ***************************' })
1313
const filePath = path.join(__dirname, '/temp/')
14-
const data = fs.readFileSync(filePath + 'jobCandidate-backup.json', 'utf-8')
15-
const jobCandidates = JSON.parse(data)
16-
let summary = 0
17-
for (var i = 0; i < jobCandidates.length; i++) {
18-
const jc = await JobCandidate.findById(jobCandidates[i].id)
19-
if (jc) {
20-
const oldStatus = jc.status
21-
const updated = await jc.update({ status: jobCandidates[i].status })
22-
summary++
23-
logger.info({ component: currentStep, message: `jobCandidate with ${jc.id} status restored from ${oldStatus} to ${updated.status}` })
24-
}
25-
};
26-
logger.info({ component: currentStep, message: `Totally restored ${summary} jobCandidates` })
14+
const files = []
15+
fs.readdirSync(filePath).forEach(async (file) => {
16+
files.push(`${filePath}${file}`)
17+
})
18+
let totalSum = 0
19+
for (let j = 0; j < files.length; j++) {
20+
const data = fs.readFileSync(files[j], 'utf-8')
21+
const jobCandidates = JSON.parse(data)
22+
let summary = 0
23+
for (var i = 0; i < jobCandidates.length; i++) {
24+
const jc = await JobCandidate.findById(jobCandidates[i].id)
25+
if (jc) {
26+
const oldStatus = jc.status
27+
const updated = await jc.update({ status: jobCandidates[i].status })
28+
summary++
29+
totalSum++
30+
logger.info({ component: currentStep, message: `jobCandidate with ${jc.id} status restored from ${oldStatus} to ${updated.status}` })
31+
}
32+
};
33+
logger.info({ component: `${currentStep} Sub`, message: `Restored ${summary} jobCandidates from ${files[j]}` })
34+
}
35+
logger.info({ component: currentStep, message: `Report: Totally restored ${totalSum} jobCandidates` })
2736
logger.info({ component: currentStep, message: '*************************** Restore process finished ***************************' })
2837
}
2938

0 commit comments

Comments
 (0)