Fixed database update - general improvements
This commit is contained in:
@@ -22,8 +22,8 @@ public class HandleDbBackup
|
|||||||
var stream = new MemoryStream(bytes);
|
var stream = new MemoryStream(bytes);
|
||||||
var postCount = await _db.CountDocumentsAsync(new BsonDocument());
|
var postCount = await _db.CountDocumentsAsync(new BsonDocument());
|
||||||
var caption =
|
var caption =
|
||||||
$"Backup of the database {dbname}<br>Created at {DateTime.Now:yyyy-MM-dd HH:mm:ss}<br>Current post count: {postCount}";
|
$"Backup of the database: {dbname}\nCreated at {DateTime.Now:yyyy-MM-dd HH:mm:ss}\nCurrent post count: {postCount}";
|
||||||
await _bot.SendDocument(adminId, InputFile.FromStream(stream, "backup.json"), caption, ParseMode.Html);
|
await _bot.SendDocument(adminId, InputFile.FromStream(stream, "backup.json"), caption);
|
||||||
logger?.LogInformation("Backup sent");
|
logger?.LogInformation("Backup sent");
|
||||||
}
|
}
|
||||||
catch(Exception ex){
|
catch(Exception ex){
|
||||||
|
@@ -15,9 +15,10 @@ public sealed class PostResolver
|
|||||||
var response = await _httpClient.GetAsync(requestUrl);
|
var response = await _httpClient.GetAsync(requestUrl);
|
||||||
|
|
||||||
// Print out ratelimit info
|
// Print out ratelimit info
|
||||||
logger?.LogInformation("Remaining requests: " +
|
var remainingTime = int.Parse(response.Headers.GetValues("X-RateLimit-Remaining").First());
|
||||||
response.Headers.GetValues("X-RateLimit-Remaining").First() + "time to reset: " +
|
var resetTime = DateTime.Parse(response.Headers.GetValues("X-RateLimit-Reset").First());
|
||||||
response.Headers.GetValues("X-RateLimit-Reset").First());
|
var diff = resetTime - DateTime.UtcNow;
|
||||||
|
logger?.LogInformation($"Remaining requests: {remainingTime}, ratelimit reset in {diff.Hours} hours {diff.Minutes} minutes {diff.Seconds} seconds");
|
||||||
|
|
||||||
// Check if response is ok
|
// Check if response is ok
|
||||||
if (
|
if (
|
||||||
|
@@ -48,7 +48,11 @@ public class ProcessPosts
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert post
|
// Insert post
|
||||||
|
if (validPosts.Count != 0)
|
||||||
|
{
|
||||||
await _db.InsertManyAsync(validPosts);
|
await _db.InsertManyAsync(validPosts);
|
||||||
|
}
|
||||||
|
|
||||||
logger?.LogInformation(
|
logger?.LogInformation(
|
||||||
$"Proccesing done, stats: received {fetchedPosts.Count} posts, inserted and sent {newPosts} new posts.");
|
$"Proccesing done, stats: received {fetchedPosts.Count} posts, inserted and sent {newPosts} new posts.");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user