Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
I
install.api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Script
install.api
Commits
81fd2288
Commit
81fd2288
authored
Jun 20, 2020
by
jinkaiqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增超时检测装饰器和应用修改修复bug
parent
9c48f7cf
Pipeline
#25159
passed with stage
in 22 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
12 deletions
+28
-12
application_service.py
app/application/application_service.py
+10
-9
upgrade_service.py
app/upgrade/upgrade_service.py
+1
-1
common_tools.py
app/utils/common_tools.py
+17
-2
No files found.
app/application/application_service.py
View file @
81fd2288
...
...
@@ -4,10 +4,11 @@ import os
import
re
import
time
from
func_timeout
import
func_set_timeout
from
git
import
GitCommandError
from
app.conncetion.conncetion_service
import
ConnectionService
from
app.utils.common_tools
import
CommonTools
from
app.utils.common_tools
import
CommonTools
,
time_out
from
app.utils.db_tools
import
db_driver
from
flask_app
import
git_path
,
repo
from
huansi_utils.exception.exception
import
HSException
...
...
@@ -118,13 +119,13 @@ where B.default_version=1'''
with
open
(
download_log_path
,
'a+'
)
as
f
:
log_content
=
f
.
read
()
log_content
=
f
"{log_content}{time.strftime('
%
Y-
%
m-
%
d
%
H:
%
M:
%
S',time.localtime(time.time()))}===>[{app_list_str}]"
log_content
=
f
"{log_content}{time.strftime('
%
Y-
%
m-
%
d
%
H:
%
M:
%
S',
time.localtime(time.time()))}===>[{app_list_str}]"
with
open
(
download_log_path
,
'w'
,
encoding
=
'utf8'
)
as
f
:
f
.
write
(
log_content
)
repo
.
git
.
add
([
self
.
compose_path
,
download_log_path
])
repo
.
git
.
commit
(
f
"-m {time.strftime('
%
Y-
%
m-
%
d
%
H:
%
M:
%
S',time.localtime(time.time()))}===>[{app_list_str}]"
)
repo
.
git
.
commit
(
f
"-m {time.strftime('
%
Y-
%
m-
%
d
%
H:
%
M:
%
S',
time.localtime(time.time()))}===>[{app_list_str}]"
)
repo
.
git
.
push
()
def
get_port_list
(
self
,
project_no
):
...
...
@@ -196,20 +197,19 @@ where B.default_version=1'''
info_dict
=
{}
info_dict
[
'port'
]
=
port_info
[
'port'
]
info_dict
[
'app_code'
]
=
port_info
[
'app_code'
]
try
:
self
.
test_connect_port
(
host_ip
,
port_info
[
'port'
])
if
self
.
test_connect_port
(
host_ip
,
port_info
[
'port'
]):
info_dict
[
'status'
]
=
'测试通过'
info_list_success
.
append
(
info_dict
)
e
xcept
Exception
:
e
lse
:
info_dict
[
'status'
]
=
'测试失败'
info_list_fail
.
append
(
info_dict
)
# info_list.append(info_dict)
info_list
=
info_list_fail
+
info_list_success
return
info_list
import
timeout_decorator
# 超过两秒,基本上没救了,告辞~~~~
@
timeout_decorator
.
timeout
(
2
)
@
time_out
@
func_set_timeout
(
2
)
def
test_connect_port
(
self
,
ip
,
port
):
'''
检查端口是否开放
...
...
@@ -224,5 +224,6 @@ where B.default_version=1'''
try
:
sk
.
connect
((
ip
,
int
(
port
)))
sk
.
shutdown
(
2
)
return
True
finally
:
sk
.
close
()
app/upgrade/upgrade_service.py
View file @
81fd2288
...
...
@@ -454,7 +454,7 @@ docker-compose -f /data/upgrade_tools_data/backup/{upgrade_no}/docker-compose.ym
out
,
err
=
ssh
.
exec_command
(
f
'''export HUANSI_REGISTRY_URL=47.110.145.204:8084 &&
\
source /etc/profile.d/huansi.sh &&
\
docker-compose -f /data/upgrade_tools_data/backup/{upgrade_no}/docker-compose.yml -p deploy
restart -t 100
'''
)
docker-compose -f /data/upgrade_tools_data/backup/{upgrade_no}/docker-compose.yml -p deploy
up -d --force-recreate
'''
)
logger
.
info
(
f
'应用操作信息:{out},其他信息:{err}'
)
logger
.
info
(
"应用修改成功"
)
...
...
app/utils/common_tools.py
View file @
81fd2288
# -*- coding:utf-8 -*-
import
os
import
timeout_decorator
from
func_timeout
import
func_set_timeout
,
FunctionTimedOut
from
huansi_utils.app.apploader
import
logger
from
huansi_utils.exception.exception
import
HSException
def
time_out
(
fn
,
*
args
,
**
kwargs
):
def
wrapper
(
*
args
,
**
kwargs
):
try
:
result
=
fn
(
*
args
,
**
kwargs
)
return
result
except
FunctionTimedOut
:
print
(
'timeout'
)
return
False
return
wrapper
class
CommonTools
:
@
classmethod
def
validate_dict_value_all_not_none
(
cls
,
dict_data
:
dict
,
mapping
=
None
):
...
...
@@ -23,6 +35,8 @@ class CommonTools:
# 超过四秒,基本上没救了,告辞~~~~
# @timeout_decorator.timeout(2)
@
time_out
@
func_set_timeout
(
2
)
def
test_db_connection
(
self
,
ip
:
int
,
port
:
int
,
user_name
:
str
,
password
:
str
,
db_name
:
str
):
'''
测试数据库连接
...
...
@@ -56,7 +70,8 @@ class CommonTools:
return
False
except
Exception
as
e
:
if
isinstance
(
e
,
timeout_decorator
.
TimeoutError
):
from
func_timeout
import
FunctionTimedOut
if
isinstance
(
e
,
FunctionTimedOut
):
logger
.
error
(
"数据库连接失败,失败原因:{}"
.
format
(
e
))
return
False
orig
=
getattr
(
e
,
'orig'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment