add suicide to worker as well

This commit is contained in:
BennyThink 2022-01-25 09:32:42 +08:00
parent f3ca4437ea
commit e915a33219
No known key found for this signature in database
GPG Key ID: 6CD0DBDA5235D481
6 changed files with 40 additions and 5 deletions

View File

@ -15,4 +15,4 @@ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY . /ytdlbot
CMD ["/usr/local/bin/supervisord", "-c" ,"/ytdlbot/conf/supervisor.conf"]
CMD ["/usr/local/bin/supervisord", "-c" ,"/ytdlbot/conf/supervisor_main.conf"]

View File

@ -0,0 +1,28 @@
[supervisord]
nodaemon=true
logfile=/dev/null
logfile_maxbytes=0
user=root
[program:worker]
directory=/ytdlbot/ytdlbot/
command=python tasks.py
autorestart=true
priority=900
stopasgroup=true
redirect_stderr=true
stdout_logfile_maxbytes = 50MB
stdout_logfile_backups = 2
stdout_logfile = /var/log/ytdl.log
[program:log]
command=tail -f /var/log/ytdl.log
autorestart=true
priority=999
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0

View File

@ -6,6 +6,6 @@ services:
env_file:
- env/ytdl.env
restart: always
command: [ "python" ,"tasks.py" ]
command: ["/usr/local/bin/supervisord", "-c" ,"/ytdlbot/conf/supervisor_worker.conf"]
volumes:
- ./data/instagram.com_cookies.txt:/ytdlbot/ytdlbot/instagram.com_cookies.txt

View File

@ -20,6 +20,7 @@ import requests
from celery import Celery
from pyrogram import idle
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from apscheduler.schedulers.background import BackgroundScheduler
from client_init import create_app
from config import BROKER, ENABLE_CELERY, ENABLE_VIP, OWNER, WORKERS
@ -27,12 +28,13 @@ from constant import BotText
from db import Redis
from downloader import convert_flac, sizeof_fmt, upload_hook, ytdl_download
from limit import VIP
from utils import (apply_log_formatter, customize_logger, get_metadata,
get_user_settings)
from utils import (apply_log_formatter, auto_restart, customize_logger,
get_metadata, get_user_settings)
customize_logger(["pyrogram.client", "pyrogram.session.session", "pyrogram.connection.connection"])
apply_log_formatter()
bot_text = BotText()
logging.getLogger('apscheduler.executors.default').propagate = False
# celery -A tasks worker --loglevel=info --pool=solo
# app = Celery('celery', broker=BROKER, accept_content=['pickle'], task_serializer='pickle')
@ -240,5 +242,10 @@ if __name__ == '__main__':
print("Bootstrapping Celery worker now.....")
time.sleep(5)
threading.Thread(target=run_celery, daemon=True).start()
scheduler = BackgroundScheduler(timezone="Asia/Shanghai")
scheduler.add_job(auto_restart, 'interval', seconds=5)
scheduler.start()
idle()
celery_client.stop()

View File

@ -188,7 +188,7 @@ class Detector:
def updates_too_long_detector(self):
# If you're seeing this, that means you have logged more than 10 device
# and this earliest account was kicked out. Restart the program could get you back in.
indicators = ["types.UpdatesTooLong"]
indicators = ["types.UpdatesTooLong", "Got shutdown from remote"]
for indicator in indicators:
if indicator in self.logs:
logging.warning("Potential crash detected by %s, it's time to commit suicide...", self.func_name())