mirror of
https://github.com/Websoft9/websoft9.git
synced 2024-11-25 17:10:27 +00:00
add cron task
This commit is contained in:
parent
d52812a9c9
commit
67c911c70b
4 changed files with 54 additions and 6 deletions
|
@ -10,7 +10,7 @@ COPY static ./static
|
|||
COPY requirements.txt main.py ./
|
||||
RUN apt update
|
||||
|
||||
# Install supervisord
|
||||
# Install supervisords
|
||||
RUN apt install -y supervisor
|
||||
COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
COPY config/cmd.sh /cmd.sh
|
||||
|
|
|
@ -21,6 +21,8 @@ from redis import Redis
|
|||
from rq import Queue, Worker, Connection
|
||||
from rq.registry import StartedJobRegistry, FinishedJobRegistry, DeferredJobRegistry, FailedJobRegistry, ScheduledJobRegistry, CanceledJobRegistry
|
||||
from api.exception.command_exception import CommandException
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from apscheduler.triggers.interval import IntervalTrigger,CronTrigger
|
||||
|
||||
# 指定 Redis 容器的主机名和端口
|
||||
redis_conn = Redis(host='websoft9-redis', port=6379)
|
||||
|
@ -28,6 +30,15 @@ redis_conn = Redis(host='websoft9-redis', port=6379)
|
|||
# 使用指定的 Redis 连接创建 RQ 队列
|
||||
q = Queue(connection=redis_conn, default_timeout=3600)
|
||||
|
||||
def auto_update():
|
||||
shell_execute.execute_command_output_all("wget https://websoft9.github.io/StackHub/install/update_appstore.sh && bash update_appstore.sh 1>/dev/null 2>&1")
|
||||
|
||||
def test():
|
||||
shell_execute.execute_command_output_all("echo 1111 >> /tmp/xuweitest")
|
||||
|
||||
scheduler = BackgroundScheduler()
|
||||
#scheduler.add_job(auto_update, CronTrigger(hour=1, minute=0))
|
||||
scheduler.add_job(test, IntervalTrigger(minutes=1))
|
||||
|
||||
# 获取github文件内容
|
||||
def get_github_content(repo, path):
|
||||
|
@ -38,6 +49,17 @@ def get_github_content(repo, path):
|
|||
contents = response.text
|
||||
return contents
|
||||
|
||||
def AppAutoUpdate(auto_update):
|
||||
|
||||
if auto_update:
|
||||
scheduler.start()
|
||||
return "软件商店自动更新已经开启"
|
||||
else:
|
||||
scheduler.shutdown()
|
||||
return "软件商店自动更新已经关闭"
|
||||
|
||||
|
||||
|
||||
# 更新软件商店
|
||||
def AppStoreUpdate():
|
||||
local_path = '/data/library/install/version.json'
|
||||
|
|
|
@ -50,21 +50,23 @@ info = "  app_id:应用ID,\n\n  app_name:应用名,\n\n"
|
|||
|
||||
domain = "  Domain_set:{\n\n" \
|
||||
"    domains:域名列表\n\n" \
|
||||
"    default_domain:默认域名\n\n  }\n\n}"
|
||||
"    default_domain:默认域名\n\n  }\n\n}\n\n"
|
||||
|
||||
update = "  Update_content: {\n\n" \
|
||||
"    version: 最新版本\n\n" \
|
||||
"    date: 更新日期\n\n" \
|
||||
"    content: 更新内容\n\n  }\n\n}"
|
||||
"    content: 更新内容\n\n  }\n\n}\n\n"
|
||||
|
||||
appstore_update = "  Update_content: [] 更新内容\n\n  \n\n}"
|
||||
appstore_update = "  Update_content: [] 更新内容\n\n  \n\n}\n\n"
|
||||
auto = "  auto_update: 目前的自动更新状态\n\n  \n\n}\n\n"
|
||||
|
||||
rd = rd_s + rd_m + rd_e
|
||||
rd_info = rd_s + info + rd_e
|
||||
rd_status = rd_s + rd_status + rd_e
|
||||
rd_domain = rd_s + domain + rd_e
|
||||
rd_update_list = rd_s + update + rd_e
|
||||
|
||||
rd_appstore = rd_s + appstore_update + rd_e
|
||||
rd_auto_list = rd_s + auto + rd_e
|
||||
|
||||
@router.api_route("/AppStatus", methods=["GET", "POST"], summary="获取指定APP的信息",
|
||||
response_description=rd_status,
|
||||
|
@ -374,7 +376,7 @@ def AppUpdateList(request: Request):
|
|||
|
||||
return response
|
||||
|
||||
@router.api_route("/AppStoreUpdate", methods=["GET", "POST"], summary="更新软件商店", response_model=Response, response_description=rd_update_list)
|
||||
@router.api_route("/AppStoreUpdate", methods=["GET", "POST"], summary="更新软件商店", response_model=Response, response_description=rd_appstore)
|
||||
def AppStoreUpdate(request: Request):
|
||||
|
||||
try:
|
||||
|
@ -398,6 +400,29 @@ def AppStoreUpdate(request: Request):
|
|||
|
||||
return response
|
||||
|
||||
@router.api_route("/AppAutoUpdate", methods=["GET", "POST"], summary="软件商店自动更新", response_model=Response, response_description=rd_auto_list)
|
||||
def AppAutoUpdate(request: Request,auto_update: Optional[bool] = Query(default=False, description="自动更新标志")):
|
||||
|
||||
try:
|
||||
myLogger.info_logger("Receive request: /AppAutoUpdate")
|
||||
get_headers(request)
|
||||
ret = {}
|
||||
ret['ResponseData'] = {}
|
||||
ret['ResponseData']['auto_update'] = manage.AppAutoUpdate(auto_update)
|
||||
response = JSONResponse(content=ret)
|
||||
except CommandException as ce:
|
||||
ret = {}
|
||||
ret['ResponseData'] = {}
|
||||
ret['Error'] = manage.get_error_info(ce.code, ce.message, ce.detail)
|
||||
response = JSONResponse(content=ret)
|
||||
except Exception as e:
|
||||
ret = {}
|
||||
ret['ResponseData'] = {}
|
||||
ret['Error'] = manage.get_error_info(const.ERROR_SERVER_SYSTEM, "system original error", str(e))
|
||||
response = JSONResponse(content=ret)
|
||||
|
||||
return response
|
||||
|
||||
def get_headers(request):
|
||||
headers = request.headers
|
||||
try:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
fastapi
|
||||
uvicorn
|
||||
rq
|
||||
apscheduler
|
||||
docker
|
||||
psutil
|
||||
gunicorn
|
||||
|
|
Loading…
Reference in a new issue