Skip to content

Commit

Permalink
fix: use cfg.logger and meaningful fn name for pRetry of saveBatch
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Dec 8, 2021
1 parent 97669c1 commit 74cfc29
Show file tree
Hide file tree
Showing 2 changed files with 987 additions and 855 deletions.
7 changes: 6 additions & 1 deletion src/datastore.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,25 @@ export class DatastoreDB extends BaseCommonDB implements CommonDB {
// Here we retry the GOAWAY errors that are somewhat common for Datastore
// Currently only retrying them here in .saveBatch(), cause probably they're only thrown when saving
predicate: err => RETRY_ON.some(s => (err as Error)?.message.includes(s)),
name: `DatastoreLib.saveBatch(${table})`,
maxAttempts: 5,
delay: 5000,
delayMultiplier: 2,
logFirstAttempt: false,
logFailures: true,
// logAll: true,
logger: this.cfg.logger,
},
)

try {
await pMap(_chunk(entities, MAX_ITEMS), async batch => await save(batch))
} catch (err) {
// console.log(`datastore.save ${kind}`, { obj, entity })
this.cfg.logger.error(`error in datastore.save for ${table}`, err)
this.cfg.logger.error(
`error in DatastoreLib.saveBatch for ${table} (${rows.length} rows)`,
err,
)
// don't throw, because datastore SDK makes it in separate thread, so exception will be unhandled otherwise
return await Promise.reject(err)
}
Expand Down
Loading

0 comments on commit 74cfc29

Please sign in to comment.