This repository was archived by the owner on Jan 8, 2022. It is now read-only.
feat: added @discordjs/sharder module#87
Draft
kyranet wants to merge 6 commits intodiscordjs:mainfrom
Draft
Conversation
Codecov Report
@@ Coverage Diff @@
## main #87 +/- ##
==========================================
- Coverage 89.03% 88.95% -0.09%
==========================================
Files 9 9
Lines 1487 1566 +79
Branches 153 162 +9
==========================================
+ Hits 1324 1393 +69
- Misses 12 13 +1
- Partials 151 160 +9
Continue to review full report at Codecov.
|
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please describe the changes this PR makes and why it should be merged:
I heard you wanted a nice and complete sharder. 👀
Sadly, this system is not compatible with discord.js@13.3.1, but it will be for a future version! This sharder draws inspiration from the strategy and plug-in system Sapphire has largely adopted over the months, the way Kurasuta handles messages and shards separately, and the structure of Discord.js's built-in sharding manager to make the update easy, alongside a few sprinkles of my own based on my experience when building a cross-process intercommunication system.
Let's talk about this sharder's structure! It is divided in three components:
WorkerShardHandler) and forks (ForkProcessShardHandler) to cross-server clusters going thru local clusters (ClusterProcessShardHandler). Yes, you heard that. Although we'll most likely ship only the 3 local ones. You can make your own custom shard strategies.RawMessageHandler(data as-is, without converting to a Buffer or a string),JsonMessageHandler(JSON), andBinaryMessageHandler(V8 serder)... You can plug in your own ones, such as the Erlang External Term Format (ETF), YAML, TOML, etc.This clear separation between responsibilities allow for greater customization of the core functionality of the library, reducing the need to use external libraries.
And coming in the future, we'll probably release The Message Mappers, which give a final touch-up to a message, such as appending a header/footer or even, using OpenSSL to encrypt messages over the network.
Issues to handle:
respawn: booleantorespawn: number, accepting-1andInfinityfor unlimited respawns, but a number that is decreased by one on each shard until it's ready, in which case it'll reset the counter./gateway/botin the sharder, only once, and pass the data to the shards during spawn. We could also implement a query system so we can get that data from the ShardingManager without querying Discord more than once a day by caching and updating the result accordingly.Todo:
ProcessShardHandlerabstract, for the two classes below.ForkProcessShardHandler.CusterProcessShardHandler.WorkerShardHandler.RawMessageHandler.BinaryMessageHandler.fetchRecommendedShards.ShardTunnel?ShardClient?Status and versioning classification: