Skip to content

Commit

Permalink
[Bot] Add interval for trying to send new exception log
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythonic-Rainbow committed Sep 28, 2024
1 parent 3d55a29 commit c90ced6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Bot/Clash/Coc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ static async Task WaitRaidAsync()

// Raid ended
Raid[] raids = new Raid[s_raidSeason.Members!.Count];
long timestamp = ((DateTimeOffset)s_raidSeason.EndTime).ToUnixTimeSeconds();
for (int i = 0; i < s_raidSeason.Members.Count; i++)
{
ClanCapitalRaidSeasonMember attacker = s_raidSeason.Members[i];
long timestamp = ((DateTimeOffset)s_raidSeason.EndTime).ToUnixTimeSeconds();
raids[i] = new(timestamp, attacker.Tag, attacker.Attacks);
}

Expand Down
3 changes: 2 additions & 1 deletion Bot/Discord/Dc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ internal static async Task<RestUserMessage> NewExceptionLogAsync(Exception ex)

// Always waits until the exception is actually sent
return await Program.TryUntilAsync<RestUserMessage>(
async () => await s_botLog.SendMessageAsync(s_botApp.Owner.Mention, embed: emb.Build())
async () => await s_botLog.SendMessageAsync(s_botApp.Owner.Mention, embed: emb.Build()),
msRetryWaitInterval: 5000
);
}

Expand Down
5 changes: 4 additions & 1 deletion Bot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ internal static string GetExceptionStackTraceString(Exception ex)
return msg;
}

internal static async Task<T> TryUntilAsync<T>(Func<Task<T>> tryFunc, Func<Exception, Task>? repeatFunc = null)
internal static async Task<T> TryUntilAsync<T>(Func<Task<T>> tryFunc, Func<Exception, Task>? repeatFunc = null,
int msRetryWaitInterval = 0)
{
while (true)
{
Expand All @@ -66,6 +67,8 @@ internal static async Task<T> TryUntilAsync<T>(Func<Task<T>> tryFunc, Func<Excep
{
DefaultTryForeverExceptionFunc(ex);
}

await Task.Delay(msRetryWaitInterval);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Bot/Sql/Raid.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SQLite;

namespace Hyperstellar.Sql;
public class Raid(long endTime, string cocId, int count)
public class Raid(long endTime, string cocId, int count) : DbObj<Raid>
{
[PrimaryKey, NotNull]
public long EndTime { get; set; } = endTime;
Expand Down

0 comments on commit c90ced6

Please sign in to comment.