|
1 | 1 | const config = require('config')
|
2 | 2 | const logger = require('../util/logger')
|
| 3 | +const _ = require('lodash') |
3 | 4 | // const moment = require('moment')
|
4 | 5 | const { slice, union, toString, toNumber, remove } = require('lodash')
|
5 | 6 | const challengeSyncStatusService = require('../services/challengeSyncStatusService')
|
@@ -74,22 +75,28 @@ async function queueChallenges (filter) {
|
74 | 75 | let running = true
|
75 | 76 | let queuedCount = 0
|
76 | 77 |
|
| 78 | + // logger.debug(`Filter: ${JSON.stringify(filter)}`) |
77 | 79 | // get active challenges from v4
|
78 |
| - const { ids: v4IdArray } = await syncService.getV4ChallengeIds(filter) |
| 80 | + const v4response = await syncService.getV4ChallengeIds(filter) |
| 81 | + // logger.debug(`v4 Response: ${JSON.stringify(v4response)}`) |
| 82 | + const v4IdArray = _.map(_.get(v4response, 'ids', []), id => _.toNumber(id)) |
79 | 83 | // console.log('v4', v4IdArray)
|
80 |
| - // logger.debug(`v4 Array ${v4IdArray}`) |
| 84 | + // logger.debug(`v4 Array ${JSON.stringify(v4IdArray)}`) |
81 | 85 | // get active challenges from v5
|
82 |
| - const { ids: v5IdArray } = await syncService.getV5LegacyChallengeIds(filter) |
83 |
| - // logger.debug(`v5 Array ${v5IdArray}`) |
| 86 | + const v5response = await syncService.getV5LegacyChallengeIds(filter) |
| 87 | + // logger.debug(`v5 Response: ${JSON.stringify(v5response)}`) |
| 88 | + const v5IdArray = _.map(_.get(v5response, 'ids', []), id => _.toNumber(id)) |
| 89 | + // logger.debug(`v5 Array ${JSON.stringify(v5IdArray)}`) |
84 | 90 |
|
85 | 91 | // combine arrays, return unique
|
86 | 92 | const combinedArray = union(v4IdArray, v5IdArray)
|
87 | 93 | remove(combinedArray, n => toString(n) === 'NaN')
|
| 94 | + remove(combinedArray, n => toString(n) === 'null') |
88 | 95 | const totalChallengesCount = combinedArray.length
|
89 | 96 | // console.log('union length', combinedArray.length)
|
90 | 97 |
|
91 |
| - // logger.debug(`Sync :: Total to Sync ${totalChallengesCount}`) |
92 |
| - // logger.debug(`Combined Array ${combinedArray}`) |
| 98 | + logger.debug(`Sync :: Total to Sync ${totalChallengesCount}`) |
| 99 | + logger.debug(`Combined Array ${JSON.stringify(combinedArray)}`) |
93 | 100 |
|
94 | 101 | while (running) {
|
95 | 102 | if ((page * perPage) > combinedArray.length) {
|
@@ -120,10 +127,13 @@ async function queueChallengeById (legacyId, withLogging = false, force = false)
|
120 | 127 | logger.info(`Sync :: Queue challenge with ID: ${legacyId}`)
|
121 | 128 | }
|
122 | 129 |
|
| 130 | + // logger.debug(`queueChallengeById - Force Value: ${force} - Force Check: ${force === true}`) |
123 | 131 | if (force === true) {
|
124 | 132 | // forced, do it anyway
|
125 | 133 | logger.info(`Sync :: Sync of ${legacyId} is being forced`)
|
126 | 134 | return challengeSyncStatusService.queueForSync(legacyId, true)
|
| 135 | + // } else { |
| 136 | + // logger.debug(`Sync :: Sync Not Forced ${legacyId}`) |
127 | 137 | }
|
128 | 138 |
|
129 | 139 | // make sure it's not already queued
|
|
0 commit comments