mirror of
https://github.com/hanxi/xiaomusic.git
synced 2026-03-19 08:49:45 +08:00
Auto-format code 🧹🌟🤖
This commit is contained in:
@@ -2,9 +2,7 @@
|
||||
import argparse
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
|
||||
import sentry_sdk
|
||||
from sentry_sdk.integrations.asyncio import AsyncioIntegration
|
||||
@@ -36,8 +34,6 @@ ignore_logger("miservice")
|
||||
|
||||
|
||||
def main():
|
||||
import uvicorn
|
||||
|
||||
from xiaomusic import __version__
|
||||
from xiaomusic.api import HttpInit
|
||||
from xiaomusic.api import app as HttpApp
|
||||
@@ -104,7 +100,7 @@ def main():
|
||||
def filter(self, record):
|
||||
if record.exc_info:
|
||||
exc_type = record.exc_info[0]
|
||||
if exc_type and exc_type.__name__ == 'CancelledError':
|
||||
if exc_type and exc_type.__name__ == "CancelledError":
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -180,12 +176,14 @@ def main():
|
||||
print(f"Execption {e}")
|
||||
|
||||
import asyncio
|
||||
from uvicorn import Config as UvicornConfig, Server
|
||||
|
||||
from uvicorn import Config as UvicornConfig
|
||||
from uvicorn import Server
|
||||
|
||||
xiaomusic = XiaoMusic(config)
|
||||
HttpInit(xiaomusic)
|
||||
port = int(config.port)
|
||||
|
||||
|
||||
# 创建 uvicorn 配置,禁用其信号处理
|
||||
uvicorn_config = UvicornConfig(
|
||||
HttpApp,
|
||||
@@ -194,19 +192,20 @@ def main():
|
||||
log_config=LOGGING_CONFIG,
|
||||
)
|
||||
server = Server(uvicorn_config)
|
||||
|
||||
|
||||
# 自定义信号处理
|
||||
shutdown_initiated = False
|
||||
|
||||
def handle_exit(signum, frame):
|
||||
nonlocal shutdown_initiated
|
||||
if not shutdown_initiated:
|
||||
shutdown_initiated = True
|
||||
print("\n正在关闭服务器...")
|
||||
server.should_exit = True
|
||||
|
||||
|
||||
signal.signal(signal.SIGINT, handle_exit)
|
||||
signal.signal(signal.SIGTERM, handle_exit)
|
||||
|
||||
|
||||
# 运行服务器
|
||||
asyncio.run(server.serve())
|
||||
|
||||
|
||||
@@ -127,7 +127,9 @@ class ConversationPoller:
|
||||
await asyncio.sleep(5)
|
||||
continue
|
||||
|
||||
self.log.debug(f"Listening new message, timestamp: {self.last_timestamp}")
|
||||
self.log.debug(
|
||||
f"Listening new message, timestamp: {self.last_timestamp}"
|
||||
)
|
||||
# 动态获取最新的 cookie_jar
|
||||
if self.auth_manager.cookie_jar is not None:
|
||||
session._cookie_jar = self.auth_manager.cookie_jar
|
||||
@@ -146,7 +148,9 @@ class ConversationPoller:
|
||||
) or self.config.get_ask_by_mina:
|
||||
tasks.append(self.get_latest_ask_by_mina(device_id))
|
||||
else:
|
||||
tasks.append(self.get_latest_ask_from_xiaoai(session, device_id))
|
||||
tasks.append(
|
||||
self.get_latest_ask_from_xiaoai(session, device_id)
|
||||
)
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
Reference in New Issue
Block a user