Skip to content

Commit

Permalink
multitasking
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Jul 8, 2023
1 parent 9761854 commit f77164f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
26 changes: 14 additions & 12 deletions app/chain/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,20 @@ def remote_enable(self, arg_str, userid: Union[str, int] = None):
"""
if not arg_str:
return
arg_str = str(arg_str).strip()
if not arg_str.isdigit():
return
site_id = int(arg_str)
site = self.siteoper.get(site_id)
if not site:
self.post_message(title=f"站点编号 {site_id} 不存在!", userid=userid)
return
# 禁用站点
self.siteoper.update(site_id, {
"is_active": True
})
arg_strs = str(arg_str).split()
for arg_str in arg_strs:
arg_str = arg_str.strip()
if not arg_str.isdigit():
continue
site_id = int(arg_str)
site = self.siteoper.get(site_id)
if not site:
self.post_message(title=f"站点编号 {site_id} 不存在!", userid=userid)
return
# 禁用站点
self.siteoper.update(site_id, {
"is_active": True
})
# 重新发送消息
self.remote_list()

Expand Down
22 changes: 12 additions & 10 deletions app/chain/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,16 +501,18 @@ def remote_delete(self, arg_str: str, userid: Union[str, int] = None):
self.post_message(title="请输入正确的命令格式:/subscribe_delete [id],"
"[id]为订阅编号", userid=userid)
return
arg_str = arg_str.strip()
if not arg_str.isdigit():
return
subscribe_id = int(arg_str)
subscribe = self.subscribehelper.get(subscribe_id)
if not subscribe:
self.post_message(title=f"订阅编号 {subscribe_id} 不存在!", userid=userid)
return
# 删除订阅
self.subscribehelper.delete(subscribe_id)
arg_strs = str(arg_str).split()
for arg_str in arg_strs:
arg_str = arg_str.strip()
if not arg_str.isdigit():
continue
subscribe_id = int(arg_str)
subscribe = self.subscribehelper.get(subscribe_id)
if not subscribe:
self.post_message(title=f"订阅编号 {subscribe_id} 不存在!", userid=userid)
return
# 删除订阅
self.subscribehelper.delete(subscribe_id)
# 重新发送消息
self.remote_list()

Expand Down
5 changes: 4 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import multiprocessing

import uvicorn as uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
Expand Down Expand Up @@ -26,7 +28,8 @@
)

# uvicorn服务
Server = uvicorn.Server(Config(App, host=settings.HOST, port=settings.PORT, reload=settings.DEBUG))
Server = uvicorn.Server(Config(App, host=settings.HOST, port=settings.PORT,
reload=settings.DEBUG, workers=multiprocessing.cpu_count()))


def init_routers():
Expand Down
3 changes: 2 additions & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#user nobody;
worker_processes 1;
worker_processes auto;
worker_cpu_affinity auto;

#error_log logs/error.log;
#error_log logs/error.log notice;
Expand Down

0 comments on commit f77164f

Please sign in to comment.