Skip to content

Commit

Permalink
close connections properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ledhed2222 committed Jul 20, 2023
1 parent 9e94722 commit 8dbf31d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,27 @@ Client.ready().then(Connection => {
})

// console.dir(Transactions[0], { depth: null })
// Connection.close()
// process.exit(1)

bigquery.dataset(DATASET_NAME).table(TRANSACTION_TABLE_NAME).insert(Transactions)
.then(r => {
console.log(`Inserted rows`, r)
LastLedger = Result.ledger_index
// Connection.close()
// process.exit(0)
})
.catch(err => {
if (err && err.name === 'PartialFailureError') {
if (err.errors && err.errors.length > 0) {
console.log('Insert errors:')
err.errors.forEach(err => console.dir(err, { depth: null }))
Connection.close()
process.exit(1)
}
} else {
console.error('ERROR:', err)
Connection.close()
process.exit(1)
}
})
Expand All @@ -203,12 +207,14 @@ Client.ready().then(Connection => {
// retryTimeout = 0

if (Stopped) {
Connection.close()
return
}

return run(ledger_index + 1)
}).catch(e => {
console.log(e)
Connection.close()
process.exit(1)

// retryTimeout += 500
Expand Down Expand Up @@ -240,14 +246,14 @@ Client.ready().then(Connection => {
}
}).catch(e => {
console.log('Google BigQuery Error', e)
Connection.close()
process.exit(1)
})

process.on('SIGINT', function() {
console.log(`\nGracefully shutting down from SIGINT (Ctrl+C)\n -- Wait for remaining BigQuery inserts and XRPL Connection close...`);

Stopped = true
Connection.close()
if (LastLedger > 0) {
console.log(`\nLast ledger: [ ${LastLedger} ]\n\nRun your next job with ENV: "LEDGER=${LastLedger+1}"\n\n`)
}
Expand Down
7 changes: 6 additions & 1 deletion ledgerInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,35 @@ Client.ready().then(Connection => {
.then(r => {
console.log(`Inserted rows`, r)
LastLedger = Result.ledger_index
// Connection.close()
// process.exit(0)
})
.catch(err => {
if (err && err.name === 'PartialFailureError') {
if (err.errors && err.errors.length > 0) {
console.log('Insert errors:')
err.errors.forEach(err => console.dir(err, { depth: null }))
Connection.close()
process.exit(1)
}
} else {
console.error('ERROR:', err)
Connection.close()
process.exit(1)
}
})

// retryTimeout = 0

if (Stopped) {
Connection.close()
return
}

return run(ledger_index + 1)
}).catch(e => {
console.log(e)
Connection.close()
process.exit(1)

// retryTimeout += 500
Expand Down Expand Up @@ -107,14 +112,14 @@ Client.ready().then(Connection => {
}
}).catch(e => {
console.log('Google BigQuery Error', e)
Connection.close()
process.exit(1)
})

process.on('SIGINT', function() {
console.log(`\nGracefully shutting down from SIGINT (Ctrl+C)\n -- Wait for remaining BigQuery inserts and XRPL Connection close...`);

Stopped = true
Connection.close()
if (LastLedger > 0) {
console.log(`\nLast ledger: [ ${LastLedger} ]\n\nRun your next job with ENV: "LEDGER=${LastLedger+1}"\n\n`)
}
Expand Down

0 comments on commit 8dbf31d

Please sign in to comment.