-
Notifications
You must be signed in to change notification settings - Fork 628
Clean up ShardManager/Queuer/Runner #2653
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
Conversation
97a9f68 to
c0a9436
Compare
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.
Since ShardManager::{restart, restart_shard} are public functions, relying on the user to make sure that ShardInfo::total is correct seems brittle. Maybe ShardManager::shard_total could be kept and changed to type Arc<u32>? It's only set on initialization and never changed, and therefore could be kept immutable this way.
c0a9436 to
ec6d247
Compare
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.
Ok, so rather than an Arc<u32>, I figured the best way to avoid breaking the signatures of restart and restart_shard is to have shard_total be a OnceLock<u32> that gets filled inside ShardManager::initialize and is fetched inside ShardManager::boot.
ec6d247 to
1ace66e
Compare
1ace66e to
db344cb
Compare
|
Right then, fixed your concerns by making |
db344cb to
1d7a2e1
Compare
|
Changing to |
|
It infecting the API for Client is somewhat intentional, it is an invariant of the API that was previously not encoded and is now in the type system. |
That's true, but do you think the panic could be moved inside the function by converting from a |
|
If I wanted mistakes in my code to become problems at runtime, instead of compile time, I would be writing in python. I can make it panic if 0 inside the serenity code but I very much recommend against. Id::new panicking is fine enough because it's done so often and isn't likely to have a person give it |
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.
Initial brief review of the new changes. The shard total is being incorrectly initialized IMO. The intention is that it should be either specified manually, or default to the value provided by the gateway. Right now it can't be manually overridden.
One way to fix this is to introduce a new ShardQueuerMessage variant that can override the value of ShardQueuer::shard_total. Then, Client::start_autosharded won't have to fire a duplicate request to the gateway.
I don't like that ShardManagerOptions::shard_total exists solely to get the value into the ShardQueuer, but I guess changing to using a OnceLock would mean that Client::start_autosharded would be the place that initializes it, meaning a duplicate gateway request.
As for the NonZeroU16 thing, all I'll say is that in the string NonZeroU16::new(1).expect("1 != 0"), out of the 35 total characters, only a single one is relevant. And, I'm sure there are plenty of other values serenity receives from the API that can never be 0 which aren't tracked as non-zero. Ultimately, the tradeoff of noisiness here is pretty stark to me, and not worth it.
1d7a2e1 to
b4b1294
Compare
b4b1294 to
902582a
Compare
|
Followed through with all your suggestions. |
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.
Thank you for all your patience and work on this PR.
Just some basic cleanups I noticed.