From aa118f7ae6592a1a4b5664f5b72a4a67327275b1 Mon Sep 17 00:00:00 2001 From: David Guillen Fandos Date: Thu, 17 Jun 2021 21:36:46 +0200 Subject: [PATCH] Add knob to control the file expiration timeout. This allows tweaking the value (from the default 1h timeout) so that loaded servers do not run out of disk by setting it to a smaller value. --- docker-entrypoint.sh | 5 ++++- telegram-bot-api/Client.cpp | 3 ++- telegram-bot-api/ClientParameters.h | 1 + telegram-bot-api/telegram-bot-api.cpp | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 3a46051..b60ea98 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -56,7 +56,10 @@ if [ -n "$TELEGRAM_RELATIVE" ]; then CUSTOM_ARGS="${CUSTOM_ARGS} --relative" fi if [ -n "$TELEGRAM_MAX_BATCH" ]; then - CUSTOM_ARGS="${CUSTOM_ARGS} ---max-batch-operations=$TELEGRAM_MAX_BATCH" + CUSTOM_ARGS="${CUSTOM_ARGS} --max-batch-operations=$TELEGRAM_MAX_BATCH" +fi +if [ -n "$TELEGRAM_FILE_EXPIRATION_TIME" ]; then + CUSTOM_ARGS="${CUSTOM_ARGS} --file-expiration-time=$TELEGRAM_FILE_EXPIRATION_TIME" fi if [ -n "$TELEGRAM_LOGS" ]; then CUSTOM_ARGS="$CUSTOM_ARGS --log=${TELEGRAM_LOGS}" diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index d9e2a55..5863b50 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -4581,7 +4581,8 @@ void Client::on_update_authorization_state() { make_object(3600)), std::make_unique()); send_request(make_object("delete_file_reference_after_seconds", - make_object(3600)), + make_object( + parameters_->file_expiration_timeout_seconds_)), std::make_unique()); auto parameters = make_object(); diff --git a/telegram-bot-api/ClientParameters.h b/telegram-bot-api/ClientParameters.h index d3bffe4..1826605 100644 --- a/telegram-bot-api/ClientParameters.h +++ b/telegram-bot-api/ClientParameters.h @@ -76,6 +76,7 @@ struct ClientParameters { td::uint32 max_batch_operations = 10000; double start_time_ = 0; + td::int32 file_expiration_timeout_seconds_ = 3600; td::ActorId get_host_by_name_actor_id_; diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index 7fc6a34..e80763e 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -314,6 +314,9 @@ int main(int argc, char *argv[]) { options.add_checked_option('\0', "max-batch-operations", PSLICE() << "maximum number of batch operations (default: " << parameters->max_batch_operations << ")", td::OptionParser::parse_integer(parameters->max_batch_operations)); + options.add_checked_option('\0', "file-expiration-time", + PSLICE() << "downloaded files expire after this amount of seconds of not being used (defaults to " << parameters->file_expiration_timeout_seconds_ << ")", + td::OptionParser::parse_integer(parameters->file_expiration_timeout_seconds_)); options.add_checked_option( '\0', "proxy", PSLICE() << "HTTP proxy server for outgoing webhook requests in the format http://host:port",