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