From 459de8c00c77bf1d5908e25d4614ff0d3f596237 Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Mon, 28 Jan 2019 01:07:57 +0300 Subject: [PATCH] fix --- aggregator/client.py | 4 ++-- aggregator/tasks.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/aggregator/client.py b/aggregator/client.py index 7f17779..fdcd5d7 100644 --- a/aggregator/client.py +++ b/aggregator/client.py @@ -13,14 +13,14 @@ from aggregator.models import AggregationSource, Message, Chat Session.notice_displayed = True -def get_client(): +def get_client(takeout=False): config._reload_maybe() if not config.pyrogram_session or not config.pyrogram_app_id or not config.pyrogram_app_hash: raise RuntimeError('Pyrogram is not configured') session_path = os.path.relpath(default_storage.path(config.pyrogram_session.replace('.session', ''))) - return Client(session_path, config.pyrogram_app_id, config.pyrogram_app_hash) + return Client(session_path, config.pyrogram_app_id, config.pyrogram_app_hash, takeout=takeout) def save_message(client, message: PyrogramMessage): diff --git a/aggregator/tasks.py b/aggregator/tasks.py index a7e0fdf..0f2adbe 100644 --- a/aggregator/tasks.py +++ b/aggregator/tasks.py @@ -11,5 +11,7 @@ def collect_new_messages(chat_id): from .models import Chat chat = Chat.objects.get(pk=chat_id) - with get_client() as client: - _collect_new_messages(client, chat) + client = get_client(takeout=True) + client.start() + _collect_new_messages(client, chat) + client.stop()