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: 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 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 interval: ${TTL_MINUTES_CLEANUP_INTERVAL:-60}m
retries: 0 retries: 10
timeout: 55m timeout: 55m
volumes: volumes:
nginxcache: nginxcache:

View File

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