From ab2871a42b01f751a1e607ac7639dd008aa51aa5 Mon Sep 17 00:00:00 2001 From: BennyThink Date: Wed, 29 Dec 2021 23:18:36 +0800 Subject: [PATCH] remove celery --- .gitignore | 3 ++- docker-compose.yml | 12 ++++-------- ytdlbot/config.py | 2 -- ytdlbot/tasks.py | 29 ----------------------------- ytdlbot/ytdl_bot.py | 10 +++++----- 5 files changed, 11 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index a64a174..ad37aa2 100644 --- a/.gitignore +++ b/.gitignore @@ -153,4 +153,5 @@ dmypy.json /.idea/dataSources/bf75f0a6-c774-4ecf-9448-2086f57b70df/storage_v2/_src_/schema/main.uQUzAA.meta db_data/* env/* -.ash_history \ No newline at end of file +.ash_history +data/* \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 4eb317b..a4069c1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,7 @@ services: driver: none mysql: - image: mysql:5.7 + image: mysql/mysql-server:8.0 restart: always volumes: - ./db_data:/var/lib/mysql @@ -32,10 +32,6 @@ services: depends_on: - socat - redis - - worker: - image: bennythink/ytdlbot - env_file: - - env/ytdl.env - restart: always - command: [ "/usr/local/bin/celery" ,"-A","tasks","worker","--loglevel=info","--pool=prefork","--concurrency=200" ] + volumes: + - ./data/instagram.com_cookies.txt:/ytdlbot/instagram.com_cookies.txt + - ./data/vnstat/:/var/lib/vnstat/ diff --git a/ytdlbot/config.py b/ytdlbot/config.py index 25ca9ba..2243249 100644 --- a/ytdlbot/config.py +++ b/ytdlbot/config.py @@ -40,8 +40,6 @@ AUTHORIZED_USER: "str" = os.getenv("AUTHORIZED", "") REQUIRED_MEMBERSHIP: "str" = os.getenv("REQUIRED_MEMBERSHIP", "") # celery related -ENABLE_CELERY = os.getenv("ENABLE_CELERY", False) -BROKER = os.getenv("BROKER", f"redis://{REDIS}:6379/4") MYSQL_HOST = os.getenv("MYSQL_HOST", "localhost") MYSQL_USER = os.getenv("MYSQL_USER", "root") MYSQL_PASS = os.getenv("MYSQL_PASS", "root") diff --git a/ytdlbot/tasks.py b/ytdlbot/tasks.py index ec3f6d6..396ed73 100644 --- a/ytdlbot/tasks.py +++ b/ytdlbot/tasks.py @@ -11,13 +11,9 @@ import logging import os import pathlib import tempfile -import time -from celery import Celery from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup -from client_init import create_app -from config import BROKER, ENABLE_CELERY from constant import BotText from db import Redis from downloader import sizeof_fmt, upload_hook, ytdl_download @@ -26,28 +22,6 @@ from utils import get_metadata, get_user_settings bot_text = BotText() logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(filename)s [%(levelname)s]: %(message)s') -# celery -A tasks worker --loglevel=info --pool=solo - -# app = Celery('celery', broker=BROKER, accept_content=['pickle'], task_serializer='pickle') -app = Celery('celery', broker=BROKER) - -celery_client = create_app(app.main, 5) - - -@app.task() -def download_task(chat_id, message_id, url): - logging.info("celery tasks started for %s", url) - with celery_client: - bot_msg = celery_client.get_messages(chat_id, message_id) - normal_download(bot_msg, celery_client, url) - logging.info("celery tasks ended.") - - -def download_entrance(bot_msg, client, url): - if ENABLE_CELERY: - download_task.delay(bot_msg.chat.id, bot_msg.message_id, url) - else: - normal_download(bot_msg, client, url) def normal_download(bot_msg, client, url): @@ -103,6 +77,3 @@ def normal_download(bot_msg, client, url): temp_dir.cleanup() - -if __name__ == '__main__': - download_task("", "", "") diff --git a/ytdlbot/ytdl_bot.py b/ytdlbot/ytdl_bot.py index b465c2b..908aae1 100644 --- a/ytdlbot/ytdl_bot.py +++ b/ytdlbot/ytdl_bot.py @@ -20,13 +20,13 @@ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup from tgbot_ping import get_runtime from client_init import create_app -from config import (AUTHORIZED_USER, ENABLE_CELERY, ENABLE_VIP, OWNER, +from config import (AUTHORIZED_USER, ENABLE_VIP, OWNER, REQUIRED_MEMBERSHIP) from constant import BotText from db import MySQL, Redis from downloader import convert_flac from limit import verify_payment -from tasks import download_entrance +from tasks import normal_download from utils import customize_logger, get_user_settings, set_user_settings customize_logger(["pyrogram.client", "pyrogram.session.session", "pyrogram.client", "pyrogram.connection.connection"]) @@ -93,7 +93,7 @@ def ping_handler(client: "Client", message: "types.Message"): if os.uname().sysname == "Darwin" or ".heroku" in os.getenv("PYTHONHOME", ""): bot_info = "ping unavailable." else: - bot_info = get_runtime("botsrunner_ytdl_1", "YouTube-dl") + bot_info = get_runtime("ytdlbot_ytdl_1", "YouTube-dl") if message.chat.username == OWNER: client.send_document(chat_id, Redis().generate_file(), caption=bot_info) else: @@ -169,7 +169,7 @@ def download_handler(client: "Client", message: "types.Message"): bot_msg: typing.Union["types.Message", "typing.Any"] = message.reply_text("Processing", quote=True) client.send_chat_action(chat_id, 'upload_video') # temp_dir = tempfile.TemporaryDirectory() - download_entrance(bot_msg, client, url) + normal_download(bot_msg, client, url) # temp_dir.cleanup() @@ -228,7 +228,7 @@ if __name__ == '__main__': ▌ ▌ ▌ ▌ ▌ ▌ ▌ ▌ ▌ ▌ ▛▀ ▌ ▌ ▌ ▌ ▐▐▐ ▌ ▌ ▐ ▌ ▌ ▞▀▌ ▌ ▌ ▘ ▝▀ ▝▀▘ ▘ ▝▀▘ ▀▀ ▝▀▘ ▀▀ ▝▀ ▘▘ ▘ ▘ ▘ ▝▀ ▝▀▘ ▝▀▘ -By @BennyThink, VIP mode: {ENABLE_VIP}, Distribution: {ENABLE_CELERY} +By @BennyThink, VIP mode: {ENABLE_VIP} """ print(banner) app.run()