2022-08-22 01:26:36 +02:00
|
|
|
//
|
2022-12-31 22:31:16 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2022-08-22 01:26:36 +02:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#include "telegram-bot-api/Watchdog.h"
|
|
|
|
|
2022-10-09 19:16:45 +02:00
|
|
|
#include "td/utils/logging.h"
|
2022-08-22 01:26:36 +02:00
|
|
|
#include "td/utils/Time.h"
|
|
|
|
|
|
|
|
namespace telegram_bot_api {
|
|
|
|
|
|
|
|
void Watchdog::kick() {
|
|
|
|
auto now = td::Time::now();
|
2023-03-27 18:05:23 +02:00
|
|
|
if (now >= last_kick_time_ + timeout_ && last_kick_time_ > 0 && GET_VERBOSITY_LEVEL() >= VERBOSITY_NAME(ERROR)) {
|
2022-10-04 23:06:48 +02:00
|
|
|
LOG(ERROR) << get_name() << " timeout expired after " << now - last_kick_time_ << " seconds";
|
2022-08-22 01:26:36 +02:00
|
|
|
td::thread::send_real_time_signal(main_thread_id_, 2);
|
|
|
|
}
|
|
|
|
last_kick_time_ = now;
|
|
|
|
set_timeout_in(timeout_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Watchdog::timeout_expired() {
|
|
|
|
kick();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace telegram_bot_api
|