mirror of
https://github.com/omg-xtao/ytdlbot.git
synced 2025-01-30 17:58:36 +00:00
hot patch container
This commit is contained in:
parent
4fd8340da2
commit
1f5f7c8238
5
Makefile
5
Makefile
@ -46,4 +46,7 @@ ps:
|
||||
docker-compose -f docker-compose.yml -f worker.yml ps
|
||||
|
||||
down:
|
||||
docker-compose -f docker-compose.yml -f worker.yml down
|
||||
docker-compose -f docker-compose.yml -f worker.yml down
|
||||
|
||||
logs:
|
||||
docker-compose -f docker-compose.yml -f worker.yml logs -f worker ytdl
|
@ -11,14 +11,17 @@ import logging
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
import psutil
|
||||
import requests
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from celery import Celery
|
||||
from celery.worker.control import Panel
|
||||
from pyrogram import idle
|
||||
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
|
||||
@ -240,6 +243,24 @@ def ytdl_normal_download(bot_msg, client, url):
|
||||
temp_dir.cleanup()
|
||||
|
||||
|
||||
@Panel.register
|
||||
def hot_patch(*args):
|
||||
git_path = pathlib.Path().cwd().parent.as_posix()
|
||||
logging.info("Hot patching on path %s...", git_path)
|
||||
|
||||
unset = "/usr/bin/git config --unset http.https://github.com/.extraheader"
|
||||
pull_unshallow = "/usr/bin/git pull origin --unshallow"
|
||||
pull = "git pull"
|
||||
|
||||
subprocess.call(unset, shell=True, cwd=git_path)
|
||||
if subprocess.call(pull_unshallow, shell=True, cwd=git_path) != 0:
|
||||
logging.info("Already unshallow, pulling now...")
|
||||
subprocess.call(pull, shell=True, cwd=git_path)
|
||||
|
||||
logging.info("Code is updated, applying hot patch now...")
|
||||
psutil.Process().kill()
|
||||
|
||||
|
||||
def run_celery():
|
||||
argv = [
|
||||
"-A", "tasks", 'worker', '--loglevel=info',
|
||||
|
@ -24,7 +24,8 @@ from config import (AUTHORIZED_USER, ENABLE_CELERY, ENABLE_VIP, OWNER,
|
||||
from constant import BotText
|
||||
from db import InfluxDB, MySQL, Redis
|
||||
from limit import verify_payment
|
||||
from tasks import (audio_entrance, direct_download_entrance,
|
||||
from tasks import app as celery_app
|
||||
from tasks import (audio_entrance, direct_download_entrance, hot_patch,
|
||||
ytdl_download_entrance)
|
||||
from utils import (auto_restart, customize_logger, get_revision,
|
||||
get_user_settings, set_user_settings)
|
||||
@ -91,6 +92,17 @@ def help_handler(client: "Client", message: "types.Message"):
|
||||
client.send_message(chat_id, bot_text.help, disable_web_page_preview=True)
|
||||
|
||||
|
||||
@app.on_message(filters.command(["hot_patch"]))
|
||||
def help_handler(client: "Client", message: "types.Message"):
|
||||
username = message.from_user.username
|
||||
chat_id = message.chat.id
|
||||
if username == OWNER:
|
||||
celery_app.control.broadcast("hot_patch")
|
||||
client.send_chat_action(chat_id, "typing")
|
||||
client.send_message(chat_id, "Oorah!")
|
||||
hot_patch()
|
||||
|
||||
|
||||
@app.on_message(filters.command(["ping"]))
|
||||
def ping_handler(client: "Client", message: "types.Message"):
|
||||
chat_id = message.chat.id
|
||||
|
Loading…
Reference in New Issue
Block a user