mirror of
https://github.com/omg-xtao/ytdlbot.git
synced 2024-11-16 03:45:23 +00:00
remove celery
This commit is contained in:
parent
c96180540a
commit
ab2871a42b
3
.gitignore
vendored
3
.gitignore
vendored
@ -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
|
||||
.ash_history
|
||||
data/*
|
@ -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/
|
||||
|
@ -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")
|
||||
|
@ -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("", "", "")
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user