Compare commits

...

2 Commits

Author SHA1 Message Date
ale
83a28e3ad3 try catch
All checks were successful
continuous-integration/drone/push Build is passing
2024-09-21 03:14:28 +02:00
ale
f27ab20679 try catch 2024-09-21 03:07:51 +02:00

View File

@ -68,17 +68,22 @@ module.exports = async (client, apex, app) => {
requestPart(`https://${instance}/api/v1/instance/peers`)
])
if (instancelocated.length === 0) {
await client.index({
index: constant.index,
body: {
instance,
api,
nodeinfo,
blocks,
peers,
last: new Date()
}
})
try {
await client.index({
index: constant.index,
body: {
instance,
api,
nodeinfo,
blocks,
peers,
last: new Date()
}
})
} catch (e) {
console.error(e)
return
}
app.locals.created++
return await util.sendFederatedMessage(constant.nick, 'New Fediblock Instance', `Fediblock Instance ${instance} with ${json.length} blocks - https://${constant.apexdomain}#${instance}`, getAccount(api))
} else {
@ -89,18 +94,23 @@ module.exports = async (client, apex, app) => {
|| !instancelocated[0]._source.api
|| !instancelocated[0]._source.nodeinfo
|| !instancelocated[0]._source.peers) {
await client.update({
index: constant.index,
id: instancelocated[0]._id,
doc: {
api: api ? api : instancelocated[0]._source.api,
nodeinfo: nodeinfo ? nodeinfo : instancelocated[0]._source.nodeinfo,
blocks: blocks && blocks.length > 0 ? blocks : elasticinstance,
peers: peers && peers.length > 0 ? peers : instancelocated[0]._source.peers,
last: new Date()
},
doc_as_upsert: true
})
try {
await client.update({
index: constant.index,
id: instancelocated[0]._id,
doc: {
api: api ? api : instancelocated[0]._source.api,
nodeinfo: nodeinfo ? nodeinfo : instancelocated[0]._source.nodeinfo,
blocks: blocks && blocks.length > 0 ? blocks : elasticinstance,
peers: peers && peers.length > 0 ? peers : instancelocated[0]._source.peers,
last: new Date()
},
doc_as_upsert: true
})
} catch (e) {
console.error(e)
return
}
app.locals.updated++
if (instancelocated[0]._source.api && instancelocated[0]._source.api.uri && instancelocated[0]._source.api.contact_account && instancelocated[0]._source.api.contact_account.acct) {
const difference = blocks.filter(block => block.domain && block.domain.trim().length > 0 && !elasticinstance.some(instance => block.domain === instance.domain))
@ -134,17 +144,17 @@ module.exports = async (client, apex, app) => {
app.locals.scan.emit('data', 'data: ' + (app.locals.scannum > 0 ? '(' + app.locals.scannum-- + ':' + (index + 1) + '): ' + instance : ': ' + instance) + '\n\n')
app.locals.peers++
await scanInstance(instance)
global.gc()
} catch (e) {
console.error(e)
}
}
global.gc()
yield 0
} catch (e) {
global.gc()
console.error(e)
yield 1
}
global.gc()
yield 0
},
scanIndex = async (server, instancesall) => {
try {
@ -249,7 +259,7 @@ module.exports = async (client, apex, app) => {
}
await Promise.all(parts.map(async (p, i) => {
for await (const exit of scanPart(p, i)) {
console.log(`Scan finished ${server} - index ${i} - exit ${exit}`)
console.log('Done: ' + server + ' - ' + i + ' parts with exit ' + exit + '.')
}
}))
return await scanReturn()