|
@@ -16,7 +16,8 @@ from api.model.response import Response
|
|
from api.utils.common_log import myLogger
|
|
from api.utils.common_log import myLogger
|
|
from redis import Redis
|
|
from redis import Redis
|
|
from rq import Queue, Worker, Connection
|
|
from rq import Queue, Worker, Connection
|
|
-from rq.registry import StartedJobRegistry, FinishedJobRegistry, DeferredJobRegistry,FailedJobRegistry,ScheduledJobRegistry
|
|
|
|
|
|
+from rq.registry import StartedJobRegistry, FinishedJobRegistry, DeferredJobRegistry, FailedJobRegistry, \
|
|
|
|
+ ScheduledJobRegistry
|
|
|
|
|
|
# 指定 Redis 容器的主机名和端口
|
|
# 指定 Redis 容器的主机名和端口
|
|
redis_conn = Redis(host='websoft9-redis', port=6379)
|
|
redis_conn = Redis(host='websoft9-redis', port=6379)
|
|
@@ -24,6 +25,7 @@ redis_conn = Redis(host='websoft9-redis', port=6379)
|
|
# 使用指定的 Redis 连接创建 RQ 队列
|
|
# 使用指定的 Redis 连接创建 RQ 队列
|
|
q = Queue(connection=redis_conn)
|
|
q = Queue(connection=redis_conn)
|
|
|
|
|
|
|
|
+
|
|
# 获取所有app的信息
|
|
# 获取所有app的信息
|
|
def get_my_app():
|
|
def get_my_app():
|
|
ret = Response(code=const.RETURN_FAIL, message="App query failed!")
|
|
ret = Response(code=const.RETURN_FAIL, message="App query failed!")
|
|
@@ -139,6 +141,7 @@ def start_app(app_id):
|
|
ret = ret.dict()
|
|
ret = ret.dict()
|
|
return ret
|
|
return ret
|
|
|
|
|
|
|
|
+
|
|
def stop_app(app_id):
|
|
def stop_app(app_id):
|
|
ret = Response(code=const.RETURN_FAIL, message="")
|
|
ret = Response(code=const.RETURN_FAIL, message="")
|
|
if docker.check_app_id(app_id):
|
|
if docker.check_app_id(app_id):
|
|
@@ -160,6 +163,7 @@ def stop_app(app_id):
|
|
ret = ret.dict()
|
|
ret = ret.dict()
|
|
return ret
|
|
return ret
|
|
|
|
|
|
|
|
+
|
|
def restart_app(app_id):
|
|
def restart_app(app_id):
|
|
ret = Response(code=const.RETURN_FAIL, message="")
|
|
ret = Response(code=const.RETURN_FAIL, message="")
|
|
if docker.check_app_id(app_id):
|
|
if docker.check_app_id(app_id):
|
|
@@ -237,8 +241,8 @@ def prepare_app(app_name, customer_app_name):
|
|
code = const.RETURN_FAIL
|
|
code = const.RETURN_FAIL
|
|
return code, message
|
|
return code, message
|
|
|
|
|
|
-def install_app_delay(app_name, customer_app_name, app_version):
|
|
|
|
|
|
|
|
|
|
+def install_app_delay(app_name, customer_app_name, app_version):
|
|
try:
|
|
try:
|
|
code, message = check_app(app_name, customer_app_name, app_version)
|
|
code, message = check_app(app_name, customer_app_name, app_version)
|
|
if code == const.RETURN_SUCCESS:
|
|
if code == const.RETURN_SUCCESS:
|
|
@@ -258,15 +262,15 @@ def install_app_delay(app_name, customer_app_name, app_version):
|
|
myLogger.info_logger(output["code"])
|
|
myLogger.info_logger(output["code"])
|
|
myLogger.info_logger(output["result"])
|
|
myLogger.info_logger(output["result"])
|
|
if int(output["code"]) != 0 or "error" in output["result"] or "fail" in output["result"]:
|
|
if int(output["code"]) != 0 or "error" in output["result"] or "fail" in output["result"]:
|
|
- raise Exception("installfailed!")
|
|
|
|
|
|
+ raise Exception("installfailed!")
|
|
else:
|
|
else:
|
|
- return "success"
|
|
|
|
|
|
+ return "success"
|
|
else:
|
|
else:
|
|
raise Exception("prepare_app failed")
|
|
raise Exception("prepare_app failed")
|
|
else:
|
|
else:
|
|
raise Exception("resource check failed")
|
|
raise Exception("resource check failed")
|
|
except Exception as e:
|
|
except Exception as e:
|
|
- myLogger.info_logger(customer_app_name+"install failed!")
|
|
|
|
|
|
+ myLogger.info_logger(customer_app_name + "install failed!")
|
|
myLogger.error_logger(e)
|
|
myLogger.error_logger(e)
|
|
job_id = app_name + "_" + customer_app_name
|
|
job_id = app_name + "_" + customer_app_name
|
|
try:
|
|
try:
|
|
@@ -275,6 +279,7 @@ def install_app_delay(app_name, customer_app_name, app_version):
|
|
myLogger.error_logger(e)
|
|
myLogger.error_logger(e)
|
|
return "fail"
|
|
return "fail"
|
|
|
|
|
|
|
|
+
|
|
def if_app_exits(app_id):
|
|
def if_app_exits(app_id):
|
|
app_name = app_id.split('_')[1]
|
|
app_name = app_id.split('_')[1]
|
|
real_name = app_id.split('_')[0]
|
|
real_name = app_id.split('_')[0]
|
|
@@ -320,7 +325,8 @@ def get_apps_from_compose(output_list):
|
|
password = ""
|
|
password = ""
|
|
official_app = False
|
|
official_app = False
|
|
|
|
|
|
- if app_name in ['appmanage', 'nginxproxymanager', 'redis']:
|
|
|
|
|
|
+ if app_name in ['appmanage', 'nginxproxymanager',
|
|
|
|
+ 'redis'] and app_path == '/data/apps/stackhub/docker/' + app_name:
|
|
continue
|
|
continue
|
|
# get code
|
|
# get code
|
|
case = app_info["Status"].split("(")[0] # case
|
|
case = app_info["Status"].split("(")[0] # case
|
|
@@ -397,7 +403,6 @@ def check_if_official_app(var_path):
|
|
|
|
|
|
|
|
|
|
def get_apps_from_queue():
|
|
def get_apps_from_queue():
|
|
-
|
|
|
|
myLogger.info_logger("get queque apps...")
|
|
myLogger.info_logger("get queque apps...")
|
|
# 获取 StartedJobRegistry 实例
|
|
# 获取 StartedJobRegistry 实例
|
|
registry = StartedJobRegistry(queue=q)
|
|
registry = StartedJobRegistry(queue=q)
|
|
@@ -417,24 +422,24 @@ def get_apps_from_queue():
|
|
myLogger.info_logger(wait_job_ids)
|
|
myLogger.info_logger(wait_job_ids)
|
|
myLogger.info_logger(run_job_ids)
|
|
myLogger.info_logger(run_job_ids)
|
|
myLogger.info_logger(finish_job_ids)
|
|
myLogger.info_logger(finish_job_ids)
|
|
- myLogger.info_logger(failed_jobs )
|
|
|
|
|
|
+ myLogger.info_logger(failed_jobs)
|
|
myLogger.info_logger(scheduled_jobs)
|
|
myLogger.info_logger(scheduled_jobs)
|
|
-
|
|
|
|
|
|
+
|
|
myLogger.info_logger("----------------------------------------")
|
|
myLogger.info_logger("----------------------------------------")
|
|
|
|
|
|
installing_list = []
|
|
installing_list = []
|
|
for job in run_job_ids:
|
|
for job in run_job_ids:
|
|
app = get_installing_app(job, const.APP_READY, 'installing')
|
|
app = get_installing_app(job, const.APP_READY, 'installing')
|
|
installing_list.append(app)
|
|
installing_list.append(app)
|
|
- for job in q.jobs:
|
|
|
|
|
|
+ for job in q.jobs:
|
|
app = get_installing_app(job.id, const.APP_WAIT, 'waiting')
|
|
app = get_installing_app(job.id, const.APP_WAIT, 'waiting')
|
|
installing_list.append(app)
|
|
installing_list.append(app)
|
|
for job_id in finish_job_ids:
|
|
for job_id in finish_job_ids:
|
|
job = q.fetch_job(job_id)
|
|
job = q.fetch_job(job_id)
|
|
if job.result == "fail":
|
|
if job.result == "fail":
|
|
- app = get_installing_app(job_id, const.APP_ERROR, 'error')
|
|
|
|
- installing_list.append(app)
|
|
|
|
-
|
|
|
|
|
|
+ app = get_installing_app(job_id, const.APP_ERROR, 'error')
|
|
|
|
+ installing_list.append(app)
|
|
|
|
+
|
|
return installing_list
|
|
return installing_list
|
|
|
|
|
|
|
|
|