-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #596 from tignear/feature/manual-connect-and-recon…
…nect feat(shard): manually shard connect and reconnect
- Loading branch information
Showing
5 changed files
with
203 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,45 @@ | ||
defmodule Nostrum.Shard do | ||
@moduledoc false | ||
|
||
use Supervisor | ||
use Supervisor, restart: :transient | ||
|
||
alias Nostrum.Shard.Session | ||
|
||
def start_link([_, shard_num, _total] = opts) do | ||
def start_link({:connect, [_, shard_num, _total]} = opts) do | ||
Supervisor.start_link(__MODULE__, opts, name: :"Nostrum.Shard-#{shard_num}") | ||
end | ||
|
||
def start_link( | ||
{:reconnect, | ||
%{ | ||
shard_num: shard_num, | ||
total_shards: _total_shards, | ||
gateway: _gateway, | ||
resume_gateway: _resume_gateway, | ||
seq: _seq, | ||
session: _session | ||
}} = | ||
opts | ||
) do | ||
Supervisor.start_link(__MODULE__, opts, name: :"Nostrum.Shard-#{shard_num}") | ||
end | ||
|
||
def start_link([_, _shard_num, _total] = opts) do | ||
start_link({:connect, opts}) | ||
end | ||
|
||
def init(opts) do | ||
children = [ | ||
{Session, opts} | ||
# TODO: Add per shard ratelimiter | ||
# TODO: Add per shard cache | ||
] | ||
|
||
Supervisor.init(children, strategy: :one_for_all, max_restarts: 3, max_seconds: 60) | ||
Supervisor.init(children, | ||
strategy: :one_for_all, | ||
max_restarts: 3, | ||
max_seconds: 60, | ||
auto_shutdown: :any_significant | ||
) | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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