parent
acf411c336
commit
e2ddc3c1d4
@ -272,7 +272,7 @@ namespace NadekoBot.Modules.Administration
|
||||
return;
|
||||
}
|
||||
var pub = _cache.Redis.GetSubscriber();
|
||||
pub.Publish(_creds.RedisKey() + "_shardcoord_restart",
|
||||
pub.Publish(_creds.RedisKey() + "_shardcoord_stop",
|
||||
JsonConvert.SerializeObject(_client.ShardId),
|
||||
StackExchange.Redis.CommandFlags.FireAndForget);
|
||||
await ReplyConfirmLocalized("shard_reconnecting", Format.Bold("#" + shardid)).ConfigureAwait(false);
|
||||
|
@ -21,7 +21,7 @@ namespace NadekoBot.Core.Services.Impl
|
||||
private readonly IBotCredentials _creds;
|
||||
private readonly DateTime _started;
|
||||
|
||||
public const string BotVersion = "2.5.7";
|
||||
public const string BotVersion = "2.5.8";
|
||||
public string Author => "Kwoth#2560";
|
||||
public string Library => "Discord.Net";
|
||||
|
||||
|
@ -31,6 +31,14 @@ namespace NadekoBot.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryPeek(out int id)
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
return _queue.TryPeek(out id);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryDequeue(out int id)
|
||||
{
|
||||
lock (_locker)
|
||||
@ -90,7 +98,6 @@ namespace NadekoBot.Core.Services
|
||||
{
|
||||
//add it to the list of shards which should be started
|
||||
#if DEBUG
|
||||
|
||||
if (i > 0)
|
||||
_shardStartQueue.Enqueue(i);
|
||||
else
|
||||
@ -102,7 +109,7 @@ namespace NadekoBot.Core.Services
|
||||
var msg = _defaultShardState.Clone();
|
||||
msg.ShardId = i;
|
||||
//this is to avoid the shard coordinator thinking that
|
||||
//the shard is unresponsive while startup up
|
||||
//the shard is unresponsive while starting up
|
||||
var delay = 45;
|
||||
#if GLOBAL_NADEKO
|
||||
delay = 180;
|
||||
@ -123,12 +130,7 @@ namespace NadekoBot.Core.Services
|
||||
OnDataReceived,
|
||||
CommandFlags.FireAndForget);
|
||||
|
||||
//restart is called when shzard should be stopped and then started again
|
||||
sub.Subscribe(_key + "_shardcoord_restart",
|
||||
OnRestart,
|
||||
CommandFlags.FireAndForget);
|
||||
|
||||
//called to kill the shard
|
||||
//called to stop the shard, although the shard will start again when it finds out it's dead
|
||||
sub.Subscribe(_key + "_shardcoord_stop",
|
||||
OnStop,
|
||||
CommandFlags.FireAndForget);
|
||||
@ -160,13 +162,6 @@ namespace NadekoBot.Core.Services
|
||||
try { p?.Dispose(); } catch { }
|
||||
}
|
||||
|
||||
private void OnRestart(RedisChannel ch, RedisValue data)
|
||||
{
|
||||
var shardId = JsonConvert.DeserializeObject<int>(data);
|
||||
OnStop(shardId);
|
||||
_shardProcesses[shardId] = StartShard(shardId);
|
||||
}
|
||||
|
||||
private void OnDataReceived(RedisChannel ch, RedisValue data)
|
||||
{
|
||||
var msg = JsonConvert.DeserializeObject<ShardComMessage>(data);
|
||||
@ -220,7 +215,7 @@ namespace NadekoBot.Core.Services
|
||||
do
|
||||
{
|
||||
//start a shard which is scheduled for start every 6 seconds
|
||||
while (_shardStartQueue.TryDequeue(out var id))
|
||||
while (_shardStartQueue.TryPeek(out var id))
|
||||
{
|
||||
// if the shard is on the waiting list again
|
||||
// remove it since it's starting up now
|
||||
@ -234,8 +229,11 @@ namespace NadekoBot.Core.Services
|
||||
_log.Warn("Auto-restarting shard {0}", id);
|
||||
}
|
||||
var p = StartShard(id);
|
||||
|
||||
var toRemove = _shardProcesses[id];
|
||||
try { toRemove?.Kill(); } catch { }
|
||||
try { toRemove?.Dispose(); } catch { }
|
||||
_shardProcesses[id] = p;
|
||||
_shardStartQueue.TryDequeue(out var __);
|
||||
await Task.Delay(6000).ConfigureAwait(false);
|
||||
}
|
||||
tsc.TrySetResult(true);
|
||||
|
Loading…
Reference in New Issue
Block a user