mirror of
https://github.com/tdlib/telegram-bot-api
synced 2025-08-23 10:27:55 +00:00
Improve webhook updates delaying.
This commit is contained in:
parent
1f8116b21d
commit
72b3f6ea4d
@ -470,19 +470,24 @@ void WebhookActor::on_update_error(td::TQueue::EventId event_id, td::Slice error
|
|||||||
double now = td::Time::now();
|
double now = td::Time::now();
|
||||||
|
|
||||||
auto it = update_map_.find(event_id);
|
auto it = update_map_.find(event_id);
|
||||||
if (parameters_->shared_data_->get_unix_time(now) > it->second.expires_at_) {
|
|
||||||
|
const int MAX_RETRY_AFTER = 3600;
|
||||||
|
retry_after = td::clamp(retry_after, 0, MAX_RETRY_AFTER);
|
||||||
|
int next_delay = it->second.delay_;
|
||||||
|
int next_effective_delay = retry_after;
|
||||||
|
if (retry_after == 0 && it->second.fail_count_ > 0) {
|
||||||
|
next_delay = td::min(WEBHOOK_MAX_RESEND_TIMEOUT, next_delay * 2);
|
||||||
|
next_effective_delay = next_delay;
|
||||||
|
}
|
||||||
|
if (parameters_->shared_data_->get_unix_time(now) + next_effective_delay > it->second.expires_at_) {
|
||||||
LOG(WARNING) << "Drop update " << event_id << ": " << error;
|
LOG(WARNING) << "Drop update " << event_id << ": " << error;
|
||||||
drop_event(event_id);
|
drop_event(event_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto &update = it->second;
|
auto &update = it->second;
|
||||||
update.state_ = Update::State::Begin;
|
update.state_ = Update::State::Begin;
|
||||||
const int MAX_RETRY_AFTER = 3600;
|
update.delay_ = next_delay;
|
||||||
retry_after = td::clamp(retry_after, 0, MAX_RETRY_AFTER);
|
update.wakeup_at_ = now + next_effective_delay;
|
||||||
update.delay_ = retry_after != 0
|
|
||||||
? retry_after
|
|
||||||
: td::min(WEBHOOK_MAX_RESEND_TIMEOUT, update.delay_ * (update.fail_count_ > 0 ? 2 : 1));
|
|
||||||
update.wakeup_at_ = update.fail_count_ > 0 ? now + update.delay_ : now;
|
|
||||||
update.fail_count_++;
|
update.fail_count_++;
|
||||||
queues_.emplace(update.wakeup_at_, update.queue_id_);
|
queues_.emplace(update.wakeup_at_, update.queue_id_);
|
||||||
VLOG(webhook) << "Delay update " << event_id << " for " << (update.wakeup_at_ - now) << " seconds because of "
|
VLOG(webhook) << "Delay update " << event_id << " for " << (update.wakeup_at_ - now) << " seconds because of "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user