-
Notifications
You must be signed in to change notification settings - Fork 18
close connections properly #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: google-bigquery
Are you sure you want to change the base?
close connections properly #14
Conversation
8dbf31d to
dcd34d4
Compare
dcd34d4 to
4a24b15
Compare
index.js
Outdated
| } | ||
|
|
||
| Client.ready().then(Connection => { | ||
| Client.ready().then(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed this since I know understand that Client.ready returns Client anyway and we have that variable in global scope here. fewer variables is easier to read.
index.js
Outdated
| console.log('Insert errors:') | ||
| err.errors.forEach(err => console.dir(err, { depth: null })) | ||
| process.exit(1) | ||
| return safeHalt() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI - I personally do not like .then and greatly prefer async/await. It took me forever to remember how to await a promise from within another promise, conditionally, without nesting. to me, the fact that returning a promise from then will await the returned promise is too magical. async/await is much clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have we considered using util.promisify to wrap this callback function bigquery.dataset(DATASET_NAME).table(TRANSACTION_TABLE_NAME).insert portion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of defining safeHalt and needing to catch every possible exception and call it, have you considered using a higher level error handling in node? I think defining a process.on('uncaughtException' ... and process.on('unhandledRejection' can allow you to catch these errors on the high level and not need to do a bunch of .then code clauses on callbacks that just call safeHalt
index.js
Outdated
| console.log('Insert errors:') | ||
| err.errors.forEach(err => console.dir(err, { depth: null })) | ||
| process.exit(1) | ||
| return safeHalt() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have we considered using util.promisify to wrap this callback function bigquery.dataset(DATASET_NAME).table(TRANSACTION_TABLE_NAME).insert portion?
23fa88b to
390db6d
Compare
a9b9bad to
df1cd95
Compare
index.js
Outdated
| const txPromises = result.ledger.transactions.map((tx) => { | ||
| return client.send({ | ||
| command: 'tx', | ||
| transaction: tx, | ||
| }, xrplRequestOptions) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you potentially run into a rate limit here if you're sending a ton of client requests at the same time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you were using the promise-utils lib i linked you earlier, a mapLimit could be used to limit the number of parallel requests happening (https://blend.github.io/promise-utils/latest/index.html#maplimit)
Properly close connections and use timeouts for requests so that we actually quit when we're rate-limited and something like
systemdorforevercan handle instead of just spinning.this took a while to figure out (it was the timeouts with xrpl-client). i had to refactor everything to use
asyncto even really understand what was going on.you'll definitely want to review using "split mode", since I completely rewrote the
index.jsandledgerIndex.jsscripts