-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Allow MongoDB to be unavailable #827
Conversation
C# Unit Tests71 tests +14 71 ✅ +14 9s ⏱️ -1s Results for commit e889b07. ± Comparison against base commit 8c03571. This pull request removes 3 and adds 17 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
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.
there's some weird stuff going on in the IsAvailable
call, though I might just rewrite it to use a long delay before checking again so we don't check every single time.
_isAvailable = await Task.Run(() => | ||
{ | ||
return _mongoDatabase.RunCommandAsync((Command<BsonDocument>)"{ping:1}").Wait(100); | ||
}); |
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.
Uh, I'm not sure what you're trying to do here, but I don't think this is what you want. This will attempt to run RunCommandAsync synchronously (via the Wait) and throw if it doesn't finish in time, meanwhile you're awaiting a task that runs that async code as sync. You might want to just do this:
_isAvailable = await Task.Run(() => | |
{ | |
return _mongoDatabase.RunCommandAsync((Command<BsonDocument>)"{ping:1}").Wait(100); | |
}); | |
_isAvailable = await _mongoDatabase.RunCommandAsync((Command<BsonDocument>)"{ping:1}") | |
.WaitAsync(TimeSpan.FromMilliseconds(100)); |
this will throw if there's not a response within 100ms, so that still might not be what you want.
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.
No, Wait(100)
never throws. It returns a boolean indicating whether the command finished within the timeout:
// Returns:
// true if the System.Threading.Tasks.Task completed execution within the allotted
// time; otherwise, false.
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.
ahh ok, I forget some of them throw on timeout. It would still probably be better to catch exceptions and not use Wait as that's intended as a last resort when calling an Async method from a sync context. I'd use WaitAsync for that instead, although it throws a timeout exception when hitting the timeout.
backend/LexBoxApi/GraphQL/CustomTypes/IsLanguageForgeProjectDataLoader.cs
Outdated
Show resolved
Hide resolved
408c086
to
73e44fd
Compare
This doesn't actually seem to work currently. I'm not sure what I did in my initial testing, maybe I set _isAvailable to false explicitly while I was testing or something. Anyway, if Mongo is not up then I just get:
And it has nothing to do with my Ping/wait/etc. |
I don't love how I've implemented this.
But, LF classic is a seperate service so it seems reasonable to make it optional and have less development dependencies.
I'm not sure how to make it better.
If anyone thinks this is bad, silly or unnecessary that's fine with me.
Or is there a better way to do this?