feat: set shard status to offline when starting up
This commit is contained in:
parent
d2f29bbb51
commit
d195c80d92
@ -51,6 +51,12 @@ public class Init
|
|||||||
var bot = services.Resolve<Bot>();
|
var bot = services.Resolve<Bot>();
|
||||||
bot.Init();
|
bot.Init();
|
||||||
|
|
||||||
|
// if we're running single-process, clear any existing shard status from the database
|
||||||
|
var config = services.Resolve<BotConfig>();
|
||||||
|
var repo = services.Resolve<ModelRepository>();
|
||||||
|
if (config.Cluster == null)
|
||||||
|
await repo.ClearShardStatus();
|
||||||
|
|
||||||
// Start the Discord shards themselves (handlers already set up)
|
// Start the Discord shards themselves (handlers already set up)
|
||||||
logger.Information("Connecting to Discord");
|
logger.Information("Connecting to Discord");
|
||||||
await StartCluster(services);
|
await StartCluster(services);
|
||||||
|
@ -14,6 +14,8 @@ public partial class ModelRepository
|
|||||||
"insert into shards (id, status) values (@Id, @Status) on conflict (id) do update set status = @Status",
|
"insert into shards (id, status) values (@Id, @Status) on conflict (id) do update set status = @Status",
|
||||||
new { Id = shard, Status = status });
|
new { Id = shard, Status = status });
|
||||||
|
|
||||||
|
public Task ClearShardStatus() => _db.Execute(conn => conn.ExecuteAsync("update shards set status = 0"));
|
||||||
|
|
||||||
public Task RegisterShardHeartbeat(IPKConnection conn, int shard, Duration ping) =>
|
public Task RegisterShardHeartbeat(IPKConnection conn, int shard, Duration ping) =>
|
||||||
conn.ExecuteAsync(
|
conn.ExecuteAsync(
|
||||||
"insert into shards (id, last_heartbeat, ping) values (@Id, now(), @Ping) on conflict (id) do update set last_heartbeat = now(), ping = @Ping",
|
"insert into shards (id, last_heartbeat, ping) values (@Id, now(), @Ping) on conflict (id) do update set last_heartbeat = now(), ping = @Ping",
|
||||||
|
Loading…
Reference in New Issue
Block a user