feat: set shard status to offline when starting up
This commit is contained in:
		@@ -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",
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user