-
Notifications
You must be signed in to change notification settings - Fork 1
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
Move retry logic to mongochangestream
.
#19
base: master
Are you sure you want to change the base?
Conversation
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.
I think this will accidentally result in there not being any retries in mongo2crate.
I was looking at this recently, and I noticed that there are a couple of try/catches in syncData.ts
(example) around Crate operations, so if they fail, we're catching the error and emitting an "error" event instead. In that case, because no error is thrown, mongochangestream would not retry.
I think we need to remove the try/catches too, but it would also be good to ensure that only one "error" event is emitted at the end after the retries, which I think indicates that we need to emit the error event in mongochangestream. See my WIP PR: smartprocure/mongochangestream#30
const redis = new Redis({ keyPrefix: 'testing:' }) | ||
// MongoDB | ||
const mongoClient = await MongoClient.connect( | ||
process.env.MONGO_CONN as string |
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.
This isn't a blocker, but it would be helpful to document in the README how to set up your environment and run the tests.
// Wait for the change stream events to be processed | ||
await setTimeout(ms('6s')) | ||
const countResponse = await crate.query( | ||
`SELECT COUNT(*) FROM ${sync.qualifiedName} WHERE "createdAt" >= '${date.toISOString()}'` |
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.
Wouldn't they all be equal to date
?
@@ -14,6 +12,7 @@ import { | |||
} from './crate/util.js' | |||
|
|||
const debug = _debug('mongo2crate:crate') | |||
debug.log = console.log.bind(console) |
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.
What's the purpose of this line?
@@ -132,6 +136,7 @@ export const initSync = ( | |||
} | |||
} catch (e) { | |||
emit('error', { error: e, changeStream: true }) |
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.
Just checking my understanding: in the event of an error, we'll emit an error
event here in mongo2crate (potentially multiple times, once for each retry), then a processError
event in mongochangestream once all the retries are exhausted.
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.
Great thoughts.
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.
Looks good overall. I think the way you have it now, the scenario I mentioned on my last review won't be an issue.
mongochangestream
- Move retry logic tomongochangestream
.immutable
option.