Created
April 28, 2017 10:47
-
-
Save sizovilya/2f2636775512004c9a5e6c72e3805daa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sql.connect(config.sqlConfig).then(pool => { | |
this.pool = pool; | |
pool.request().query `select * from dbo.Groups` | |
}) | |
.then(iSuccesfullyGetGroups.bind(this), errorConnect) | |
.then(startParsing.bind(this)) | |
function iSuccesfullyGetGroups(result){ | |
const groups = result.recordset; | |
return new Promise((resolve, reject) => { | |
if (groups.length > 0) { | |
VK.auth.user().then(token => { | |
for (const group of groups) { | |
VK.call('execute.getPosts', { | |
mode: "getOffset", | |
groupId: group.GroupId, | |
topicId: group.TopicId | |
}).then(res => { | |
this.pool.request().query`UPDATE dbo.Groups SET offset = ${res.count} WHERE Id = ${group.Id}`.then(() => {resolve(true)}) | |
}).catch(err => { reject(err) }); | |
} | |
}); | |
} | |
}).bind(this); | |
} | |
function startParsing(pool) { | |
setInterval(() => { | |
pool.request().query(`select * from dbo.Groups`).then(successGetGroups.bind(this)); | |
}, 5000); | |
} | |
function errorConnect(err) { | |
console.dir(err); | |
sql.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment