fixed script to update Claim amount

This commit is contained in:
bill bittner 2017-08-15 18:24:15 -07:00
parent 4981551c59
commit bd7c6ed16a
3 changed files with 53 additions and 0 deletions

View file

@ -79,6 +79,7 @@ module.exports = {
},
resolveUri (uri) {
logger.debug(`lbryApi >> Resolving URI for "${uri}"`);
// console.log('resolving uri', uri);
return new Promise((resolve, reject) => {
axios
.post('http://localhost:5279/lbryapi', {
@ -93,6 +94,7 @@ module.exports = {
}
})
.catch(error => {
console.log('error with resolve', error);
reject(error);
});
});

View file

@ -35,6 +35,7 @@
"mysql2": "^1.3.5",
"nodemon": "^1.11.0",
"sequelize": "^4.1.0",
"sleep": "^5.1.1",
"socket.io": "^2.0.1",
"socketio-file-upload": "^0.6.0",
"universal-analytics": "^0.4.13",

50
updateClaimAmount.js Normal file
View file

@ -0,0 +1,50 @@
/*
This script will update all the records in the Claim table and update the amount.
*/
let db = require('./models');
const lbryApi = require('./helpers/lbryApi.js');
let sleep = require('sleep');
// configure logging
const config = require('config');
const logger = require('winston');
const logLevel = config.get('Logging.LogLevel');
require('./config/loggerSetup.js')(logger, logLevel);
// start the server
db.sequelize
.sync() // sync sequelize
.then(() => { // get the download directory from the daemon
console.log('db has synced');
console.log('retrieving files');
return db.Claim.findAll({where: {amount: null}});
})
.then(result => {
const totalResults = result.length;
console.log('total results found:', totalResults);
console.log('starting update...');
sleep.sleep(2);
result.forEach((record, index) => {
const uri = `${record.name}#${record.claimId}`;
setTimeout(() => {
lbryApi.resolveUri(uri)
.then(result => {
// console.log(resolveResult);
if (result['claim']) {
const amount = result['claim'].amount;
return record.update({ amount });
}
})
.then(() => {
if (index + 1 === totalResults) {
console.log('All done.');
process.exit(0);
}
})
.catch(error => console.log('error getting/setting amount >>', error));
}, 100 * index, uri);
});
})
.catch((error) => {
console.log('error getting record >>', error);
});