mirror of
https://github.com/Xahau/Validation-Ledger-Tx-Store-to-xPOP.git
synced 2025-11-04 12:25:48 +00:00
Allow for open handle detection & sigint close
This commit is contained in:
@@ -6,6 +6,7 @@ import autoindex from 'express-autoindex/dist/index.cjs.js'
|
||||
import nunjucks from 'nunjucks'
|
||||
import cors from 'cors'
|
||||
import 'dotenv/config'
|
||||
import 'wtfnode'
|
||||
|
||||
import { lastLedger } from '../lib/onLedger.mjs'
|
||||
import { txCount } from '../lib/onTransaction.mjs'
|
||||
@@ -97,7 +98,15 @@ if (!wss) {
|
||||
})
|
||||
})
|
||||
|
||||
app.listen(port)
|
||||
const server = app.listen(port)
|
||||
|
||||
// Play nice with Docker etc.
|
||||
process.on('SIGINT', () => {
|
||||
console.log('Shutting down webserver')
|
||||
server.close()
|
||||
wss.getWss().close()
|
||||
})
|
||||
|
||||
console.log('Started Event Socket Service at TCP port', port)
|
||||
} catch (e) {
|
||||
console.log('Cannot start Webserver & Event Socket Service at port', port, e)
|
||||
|
||||
31
index.mjs
31
index.mjs
@@ -4,15 +4,21 @@ import { onValidation } from './lib/onValidation.mjs'
|
||||
import { onLedger } from './lib/onLedger.mjs'
|
||||
import 'dotenv/config'
|
||||
import assert from 'assert'
|
||||
import wtf from 'wtfnode'
|
||||
import './bin/webserver.mjs'
|
||||
|
||||
let sigintEventHandler = false
|
||||
|
||||
assert(process.env?.NODES, 'ENV var missing: NODES, containing: a comma separated list of websocket endpoints')
|
||||
|
||||
await createDirectory('store')
|
||||
await createDirectory('store/xpop')
|
||||
|
||||
process.env.NODES.split(',').map(h => h.trim())
|
||||
.map(h => new XrplClient(h)).map(async c => {
|
||||
const connections = process.env.NODES.split(',').map(h => h.trim())
|
||||
.map(h => new XrplClient(h))
|
||||
|
||||
connections
|
||||
.map(async c => {
|
||||
|
||||
const subscribe = async () => {
|
||||
await c.ready()
|
||||
@@ -45,4 +51,25 @@ process.env.NODES.split(',').map(h => h.trim())
|
||||
}
|
||||
|
||||
c.on('online', () => subscribe())
|
||||
|
||||
})
|
||||
|
||||
// Play nice with Docker etc.
|
||||
if (!sigintEventHandler) {
|
||||
sigintEventHandler = true
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
connections
|
||||
.map(async c => {
|
||||
console.info('Interrupted', c.getState()?.server?.uri)
|
||||
c.close()
|
||||
})
|
||||
|
||||
if (process.env?.DEBUG) {
|
||||
// Display open handles
|
||||
console.log('-------------------')
|
||||
wtf.dump()
|
||||
console.log('-------------------' + `\n`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -43,11 +43,12 @@ const ledgerReady = async (ledger, readyElement) => {
|
||||
vl,
|
||||
validation: 0,
|
||||
ready,
|
||||
timeout: null,
|
||||
}
|
||||
})
|
||||
|
||||
// Set timeout to clean up
|
||||
setTimeout(() => {
|
||||
ledgers[ledgerIndexString].timeout = setTimeout(() => {
|
||||
// console.log('Cleaning up', ledgerIndexString)
|
||||
if (ledgers?.[ledgerIndexString]) {
|
||||
ledgers?.[ledgerIndexString]?.ledger_binary_transactions?.resolve(false)
|
||||
@@ -89,3 +90,13 @@ export {
|
||||
isLedgerReady,
|
||||
waitForLedgerReady,
|
||||
}
|
||||
|
||||
// Play nice with Docker
|
||||
process.on('SIGINT', () => {
|
||||
Object.values(ledgers).forEach(l => {
|
||||
clearTimeout(l?.timeout)
|
||||
l?.ledger_binary_transactions?.resolve(false)
|
||||
l?.ledger_info?.resolve(false)
|
||||
l?.vl?.resolve(false)
|
||||
})
|
||||
})
|
||||
|
||||
9
package-lock.json
generated
9
package-lock.json
generated
@@ -22,6 +22,7 @@
|
||||
"ripple-address-codec": "^4.3.0",
|
||||
"ripple-binary-codec": "^1.10.0",
|
||||
"ws": "^8.14.2",
|
||||
"wtfnode": "^0.9.1",
|
||||
"xrpl-client": "^2.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -5037,6 +5038,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/wtfnode": {
|
||||
"version": "0.9.1",
|
||||
"resolved": "https://registry.npmjs.org/wtfnode/-/wtfnode-0.9.1.tgz",
|
||||
"integrity": "sha512-Ip6C2KeQPl/F3aP1EfOnPoQk14Udd9lffpoqWDNH3Xt78svxPbv53ngtmtfI0q2Te3oTq79XKTnRNXVIn/GsPA==",
|
||||
"bin": {
|
||||
"wtfnode": "proxy.js"
|
||||
}
|
||||
},
|
||||
"node_modules/xrpl-client": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/xrpl-client/-/xrpl-client-2.2.0.tgz",
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
"ripple-address-codec": "^4.3.0",
|
||||
"ripple-binary-codec": "^1.10.0",
|
||||
"ws": "^8.14.2",
|
||||
"wtfnode": "^0.9.1",
|
||||
"xrpl-client": "^2.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user