2019-06-07 14:19:12 +03:00
|
|
|
require('../env')
|
2019-05-06 14:12:53 +03:00
|
|
|
const Redis = require('ioredis')
|
|
|
|
const { id } = require('../config/base.config')
|
|
|
|
const { EXIT_CODES } = require('../src/utils/constants')
|
|
|
|
|
2019-09-13 10:11:38 +03:00
|
|
|
const redis = new Redis(process.env.ORACLE_REDIS_URL)
|
2019-05-06 14:12:53 +03:00
|
|
|
|
|
|
|
redis.on('error', () => {
|
|
|
|
logError('Error: Cannot connect to redis')
|
|
|
|
})
|
|
|
|
|
|
|
|
if (process.argv.length < 4) {
|
|
|
|
logError(
|
|
|
|
'Please provide process key and new block value. Example:' +
|
|
|
|
'\n signature-request 12345 ' +
|
|
|
|
'\n collected-signatures 12345 ' +
|
|
|
|
'\n affirmation-request 12345'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function logError(message) {
|
|
|
|
console.log(message)
|
|
|
|
process.exit(EXIT_CODES.GENERAL_ERROR)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getRedisKey(name) {
|
|
|
|
return `${id}-${name}:lastProcessedBlock`
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
try {
|
|
|
|
const processName = process.argv[2]
|
|
|
|
const rawBlockValue = process.argv[3]
|
|
|
|
|
|
|
|
const newBlockValue = Number(rawBlockValue)
|
|
|
|
if (!Number.isInteger(newBlockValue)) {
|
|
|
|
logError('Expecting new block value to be an integer!')
|
|
|
|
}
|
|
|
|
|
|
|
|
const lastBlockRedisKey = getRedisKey(processName)
|
|
|
|
|
|
|
|
const value = await redis.get(lastBlockRedisKey)
|
|
|
|
|
|
|
|
if (!value) {
|
|
|
|
logError(
|
|
|
|
'Error: Process key not found on redis. Please provide one of the following:' +
|
|
|
|
'\n signature-request' +
|
|
|
|
'\n collected-signatures' +
|
|
|
|
'\n affirmation-request'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
await redis.set(lastBlockRedisKey, newBlockValue)
|
|
|
|
|
|
|
|
console.log(`${processName} last block updated to ${newBlockValue}`)
|
|
|
|
|
|
|
|
redis.disconnect()
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|