Fix counter stuck & not gen pregen xpop

This commit is contained in:
Wietse Wind
2023-10-15 00:28:38 +02:00
parent 9b73f8c408
commit 7a09ec4163
2 changed files with 45 additions and 39 deletions

View File

@@ -58,7 +58,7 @@ services:
healthcheck:
test: TTL_MINUTES_PREGEN_XPOP=${TTL_MINUTES_PREGEN_XPOP:-60} TTL_DAYS_XPOP_SOURCE_FILES=${TTL_DAYS_XPOP_SOURCE_FILES:-30} sh /cleanup.sh
interval: ${TTL_MINUTES_CLEANUP_INTERVAL:-60}m
retries: 0
retries: 10
timeout: 55m
volumes:
nginxcache:

View File

@@ -2,6 +2,7 @@ import { writeFile } from 'fs'
import { dirExists } from './dirExists.mjs'
import { ledgerIndexToFolders } from './ledgerIndexToFolders.mjs'
import { xpopGenerate } from './xpopGenerate.mjs'
import { createDirectory } from './createDirectory.mjs'
import { waitForLedgerReady } from './events/ledgerReady.mjs'
import { emit } from '../bin/webserver.mjs'
import 'dotenv/config'
@@ -68,48 +69,53 @@ const onTransaction = async ({
networkId,
txHash: tx.hash,
})
if (await dirExists(xpopBinaryDir)) {
const xpopWritten = await new Promise(resolve => {
writeFile(xpopBinaryDir + '/' + tx.hash, Buffer.from(xpopBinary, 'utf8'), err => {
if (err) {
console.log('Error writing binary XPOP', err)
resolve(false)
} else {
console.log('Wrote binary xPOP: ' + xpopBinaryDir + '/' + tx.hash)
resolve(true)
}
})
if (!(await dirExists(xpopBinaryDir))) {
console.log('(Re-) creating /store/xpop directory')
await createDirectory('store/xpop')
}
const xpopWritten = await new Promise(resolve => {
writeFile(xpopBinaryDir + '/' + tx.hash, Buffer.from(xpopBinary, 'utf8'), err => {
if (err) {
console.log('Error writing binary XPOP', err)
resolve(false)
} else {
console.log('Wrote binary xPOP: ' + xpopBinaryDir + '/' + tx.hash)
resolve(true)
}
})
if (xpopWritten) {
console.log(' ### EMIT XPOP READY FOR', tx?.Account, Number(tx.Sequence), tx.hash)
})
if (xpopWritten) {
console.log(' ### EMIT XPOP READY FOR', tx?.Account, Number(tx.Sequence), tx.hash)
txCount++
txCount++
return await emit({
account: tx?.Account,
sequence: tx.Sequence,
origin: {
tx: tx.hash,
networkId: networkId,
ledgerIndex: transaction.ledger_index,
burn: tx?.Fee,
},
destination: {
networkId: tx?.OperationLimit,
},
...(
process.env?.URL_PREFIX
? {
xpop: {
binary: `${process.env.URL_PREFIX}/xpop/${tx.hash}`,
source: `${process.env.URL_PREFIX}/${networkId}/${ledgerIndexToFolders(transaction.ledger_index)}/`,
blob: xpopBinary,
}
return await emit({
account: tx?.Account,
sequence: tx.Sequence,
origin: {
tx: tx.hash,
networkId: networkId,
ledgerIndex: transaction.ledger_index,
burn: tx?.Fee,
},
destination: {
networkId: tx?.OperationLimit,
},
...(
process.env?.URL_PREFIX
? {
xpop: {
binary: `${process.env.URL_PREFIX}/xpop/${tx.hash}`,
source: `${process.env.URL_PREFIX}/${networkId}/${ledgerIndexToFolders(transaction.ledger_index)}/`,
blob: xpopBinary,
}
: {}
)
})
}
}
: {}
)
})
}
}
}