From d9c247e5ed074ea31ace835c8933fe03334889bb Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 15 Jan 2021 16:54:14 +0300 Subject: [PATCH] Improve warning messages. --- telegram-bot-api/Client.cpp | 12 ++++++------ telegram-bot-api/Client.h | 2 +- telegram-bot-api/WebhookActor.cpp | 12 +++++------- telegram-bot-api/WebhookActor.h | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 96b19df..2df448d 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -21,7 +21,6 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/PathView.h" -#include "td/utils/port/Clocks.h" #include "td/utils/port/path.h" #include "td/utils/port/Stat.h" #include "td/utils/Random.h" @@ -3242,7 +3241,7 @@ void Client::start_up() { next_set_webhook_logging_time_ = start_time_; next_webhook_is_not_modified_warning_time_ = start_time_; previous_get_updates_start_time_ = start_time_ - 100; - previous_get_updates_finish_time_ = start_time_ - 100; + next_get_updates_conflict_time_ = start_time_ - 100; sticker_set_names_[GREAT_MINDS_SET_ID] = GREAT_MINDS_SET_NAME.str(); @@ -7592,9 +7591,9 @@ void Client::abort_long_poll(bool from_set_webhook) { void Client::fail_query_conflict(Slice message, PromisedQueryPtr &&query) { auto now = td::Time::now_cached(); - if (now >= previous_get_updates_finish_time_) { + if (now >= next_get_updates_conflict_time_) { fail_query(409, message, std::move(query)); - previous_get_updates_finish_time_ = now + 3.0; + next_get_updates_conflict_time_ = now + 3.0; } else { td::create_actor( "FailQueryConflictSleepActor", 3.0, @@ -7686,7 +7685,8 @@ void Client::do_get_updates(int32 offset, int32 limit, int32 timeout, PromisedQu } if (need_warning) { LOG(WARNING) << "Found " << updates.size() << " updates out of " << total_size << " + " << updates.size() - << " after last getUpdates call at " << previous_get_updates_finish_date_; + << " after last getUpdates call " << (td::Time::now() - previous_get_updates_finish_time_) + << " seconds ago"; } else { LOG(DEBUG) << "Found " << updates.size() << " updates out of " << total_size << " from " << from; } @@ -7702,7 +7702,7 @@ void Client::do_get_updates(int32 offset, int32 limit, int32 timeout, PromisedQu long_poll_slot_.set_timeout_at(long_poll_hard_timeout_); return; } - previous_get_updates_finish_date_ = td::Clocks::system(); // local time to output it to the log + previous_get_updates_finish_time_ = td::Time::now(); next_bot_updates_warning_time_ = td::Time::now() + BOT_UPDATES_WARNING_DELAY; if (total_size == updates.size() && was_bot_updates_warning_) { send_request(make_object(0, ""), std::make_unique()); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 42d1079..01cf068 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -922,8 +922,8 @@ class Client : public WebhookActor::Callback { int32 previous_get_updates_offset_ = -1; double previous_get_updates_start_time_ = 0; - double previous_get_updates_finish_date_ = 0; double previous_get_updates_finish_time_ = 0; + double next_get_updates_conflict_time_ = 0; td::uint64 webhook_generation_ = 1; diff --git a/telegram-bot-api/WebhookActor.cpp b/telegram-bot-api/WebhookActor.cpp index 5715fc0..77db56d 100644 --- a/telegram-bot-api/WebhookActor.cpp +++ b/telegram-bot-api/WebhookActor.cpp @@ -8,8 +8,6 @@ #include "telegram-bot-api/ClientParameters.h" -#include "td/db/TQueue.h" - #include "td/net/GetHostByNameActor.h" #include "td/net/HttpHeaderCreator.h" #include "td/net/HttpProxy.h" @@ -26,7 +24,6 @@ #include "td/utils/JsonBuilder.h" #include "td/utils/logging.h" #include "td/utils/misc.h" -#include "td/utils/port/Clocks.h" #include "td/utils/port/IPAddress.h" #include "td/utils/port/SocketFd.h" #include "td/utils/Random.h" @@ -419,9 +416,10 @@ void WebhookActor::load_updates() { } } if (need_warning) { - LOG(WARNING) << "Loaded " << updates.size() << " updates out of " << total_size << ". Have total of " - << update_map_.size() << " loaded in " << queues_.size() << " queues after last error \"" - << last_error_message_ << "\" at " << last_error_date_; + LOG(WARNING) << "Loaded " << updates.size() << " updates out of " << total_size << ". Have " << update_map_.size() + << " updates loaded in " << queue_updates_.size() << " queues after last error \"" + << last_error_message_ << "\" " << (last_error_time_ == 0 ? -1 : td::Time::now() - last_error_time_) + << " seconds ago"; } if (updates.size() == total_size && last_update_was_successful_) { @@ -741,7 +739,7 @@ void WebhookActor::on_connection_error(td::Status error) { void WebhookActor::on_webhook_error(td::Slice error) { if (was_checked_) { send_closure(callback_, &Callback::webhook_error, td::Status::Error(error)); - last_error_date_ = td::Clocks::system(); // local time to output it to the log + last_error_time_ = td::Time::now(); last_error_message_ = error.str(); } } diff --git a/telegram-bot-api/WebhookActor.h b/telegram-bot-api/WebhookActor.h index 60ab1bc..c490f8c 100644 --- a/telegram-bot-api/WebhookActor.h +++ b/telegram-bot-api/WebhookActor.h @@ -79,7 +79,7 @@ class WebhookActor : public td::HttpOutboundConnection::Callback { td::string cert_path_; std::shared_ptr parameters_; - double last_error_date_ = 0; + double last_error_time_ = 0; td::string last_error_message_ = ""; bool fix_ip_address_ = false;