mirror of
https://github.com/IT4Change/gradido.git
synced 2026-03-01 12:44:43 +00:00
insert startValidateCommunities loop
This commit is contained in:
parent
72cc65d14a
commit
290987c40c
@ -126,6 +126,7 @@ const federation = {
|
||||
: process.env.FEDERATION_COMMUNITY_URL.endsWith('/')
|
||||
? process.env.FEDERATION_COMMUNITY_URL
|
||||
: process.env.FEDERATION_COMMUNITY_URL + '/',
|
||||
FEDERATION_VALIDATE_COMMUNITY_TIMER: process.env.FEDERATION_VALIDATE_COMMUNITY_TIMER || 60000,
|
||||
}
|
||||
|
||||
const CONFIG = {
|
||||
|
||||
29
backend/src/federation/validateCommunities.ts
Normal file
29
backend/src/federation/validateCommunities.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { Community as DbCommunity } from '@entity/Community'
|
||||
import { IsNull, LessThan, Raw } from '@dbTools/typeorm'
|
||||
import { requestGetPublicKey } from './client/1_0/FederationClient'
|
||||
import { FdCommunity } from './graphql/1_0/model/FdCommunity'
|
||||
|
||||
export async function startValidateCommunities(timerInterval: number): Promise<void> {
|
||||
while (true) {
|
||||
const dbCommunities: DbCommunity[] = await DbCommunity.find({
|
||||
where: [
|
||||
{ verifiedAt: IsNull() },
|
||||
{ verifiedAt: LessThan(Raw((lastAnnouncedAt) => `${lastAnnouncedAt}`)) },
|
||||
],
|
||||
})
|
||||
if (dbCommunities) {
|
||||
dbCommunities.forEach(async function (dbCom) {
|
||||
const fdCom = new FdCommunity(dbCom)
|
||||
const pubKey = await requestGetPublicKey(fdCom)
|
||||
if (pubKey && pubKey === dbCom.publicKey.toString('hex')) {
|
||||
DbCommunity.update({ verifiedAt: new Date() }, { id: dbCom.id })
|
||||
}
|
||||
})
|
||||
}
|
||||
await sleep(timerInterval)
|
||||
}
|
||||
}
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
@ -5,6 +5,7 @@ import { startDHT } from '@/federation/index'
|
||||
|
||||
// config
|
||||
import CONFIG from './config'
|
||||
import { startValidateCommunities } from './federation/validateCommunities'
|
||||
|
||||
async function main() {
|
||||
const { app } = await createServer()
|
||||
@ -17,6 +18,7 @@ async function main() {
|
||||
console.log(`GraphIQL available at http://localhost:${CONFIG.PORT}`)
|
||||
}
|
||||
})
|
||||
startValidateCommunities(Number(CONFIG.FEDERATION_VALIDATE_COMMUNITY_TIMER))
|
||||
|
||||
// start DHT hyperswarm when DHT_TOPIC is set in .env
|
||||
if (CONFIG.FEDERATION_DHT_TOPIC) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user