Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
F
fund_report
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
彭熊
fund_report
Commits
9f5b6c0d
Commit
9f5b6c0d
authored
Jan 21, 2021
by
wang zhengwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
使用celery 替代子进程
parent
c28c8f6d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
61 deletions
+97
-61
engine.py
app/api/engine.py
+6
-1
celery.py
app/celery.py
+55
-0
report_service.py
app/service/report_service.py
+36
-60
No files found.
app/api/engine.py
View file @
9f5b6c0d
...
...
@@ -17,7 +17,7 @@ from sqlalchemy import create_engine
from
sqlalchemy.orm
import
sessionmaker
,
scoped_session
from
sqlalchemy.pool
import
NullPool
env
=
sys
.
argv
[
-
1
]
env
=
sys
.
argv
[
-
1
]
if
sys
.
argv
[
-
1
]
in
[
"dev"
,
"test"
,
"prod"
]
else
"test"
work_dir
=
os
.
getcwd
()
CFG_FILEPATH
=
work_dir
+
'/app/config/config.yaml'
...
...
@@ -95,6 +95,11 @@ redis = redis.StrictRedis(
password
=
config
[
env
][
'redis'
][
'password'
]
)
redis_host
=
config
[
env
][
'redis'
][
'host'
],
redis_port
=
config
[
env
][
'redis'
][
'port'
],
redis_db
=
config
[
env
][
'redis'
][
'db'
],
redis_password
=
config
[
env
][
'redis'
][
'password'
]
logging
.
basicConfig
(
level
=
logging
.
INFO
,
filename
=
work_dir
+
config
[
env
][
'log'
][
'filename'
],
filemode
=
config
[
env
][
'log'
][
'filemode'
],
...
...
app/celery.py
0 → 100644
View file @
9f5b6c0d
from
celery
import
Celery
from
sqlalchemy
import
and_
,
or_
from
app.api.engine
import
TAMP_SQL
,
tamp_diagnose_app_engine
,
template_folder
,
temp_img_save_folder
,
\
redis_host
,
redis_port
,
redis_db
,
redis_password
from
app.model.tamp_diagnose_app
import
HoldReport
,
HoldDiagnoseReport
,
PeriodicReport
,
Customer
,
ReportView
from
app.utils.jinjia2html_v2
import
DataIntegrate
celery_app
=
Celery
(
__name__
)
celery_conf
=
"redis://:{}@{}:{}/{}"
.
format
(
"qimeng123"
,
"118.190.63.109"
,
"56379"
,
"1"
)
celery_app
.
conf
.
update
({
"broker_url"
:
celery_conf
,
"result_backend"
:
celery_conf
})
@
celery_app
.
task
def
save_pdf
(
ifa_id
,
customer_id
,
pdf_name
,
type
,
report_data
):
"""
加法
:param x:
:param y:
:return:
"""
try
:
dt
=
DataIntegrate
(
ifa_id
=
ifa_id
,
customer_id
=
customer_id
,
pdf_name
=
pdf_name
,
type
=
type
)
dt
.
render_data
(
data
=
report_data
)
except
:
pass
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
if
type
==
1
:
res
=
tamp_diagnose_session
.
query
(
HoldReport
)
.
filter
(
and_
(
HoldReport
.
id
==
id
,
HoldReport
.
ifa_id
==
ifa_id
,
))
elif
type
==
2
:
res
=
tamp_diagnose_session
.
query
(
HoldDiagnoseReport
)
.
filter
(
and_
(
HoldDiagnoseReport
.
id
==
id
,
HoldDiagnoseReport
.
ifa_id
==
ifa_id
,
))
elif
type
==
3
:
res
=
tamp_diagnose_session
.
query
(
PeriodicReport
)
.
filter
(
and_
(
PeriodicReport
.
id
==
id
,
PeriodicReport
.
ifa_id
==
ifa_id
,
))
else
:
return
False
res
.
update
({
'file'
:
pdf_name
,
'update_status'
:
2
,
'update_time'
:
datetime
.
datetime
.
now
()
})
return
True
app/service/report_service.py
View file @
9f5b6c0d
...
...
@@ -17,6 +17,7 @@ from sqlalchemy import and_, or_
from
app.api.engine
import
TAMP_SQL
,
tamp_diagnose_app_engine
,
template_folder
,
temp_img_save_folder
from
app.model.tamp_diagnose_app
import
HoldReport
,
HoldDiagnoseReport
,
PeriodicReport
,
Customer
,
ReportView
from
app.utils.jinjia2html_v2
import
DataIntegrate
from
app.celery
import
save_pdf
def
get_report_list
(
args
):
...
...
@@ -138,68 +139,43 @@ def edit_report(args):
return
False
r
=
res
.
update
({
'report_data'
:
report_data
,
'update_status'
:
1
,
'update_time'
:
datetime
.
datetime
.
now
()
})
pid
=
os
.
fork
()
if
pid
==
0
:
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
hold_report
=
tamp_diagnose_session
.
query
(
HoldReport
)
.
filter
(
and_
(
HoldReport
.
id
==
id
,
HoldReport
.
ifa_id
==
ifa_id
,
))
hold_diagnose_report
=
tamp_diagnose_session
.
query
(
HoldDiagnoseReport
)
.
filter
(
and_
(
HoldDiagnoseReport
.
id
==
id
,
HoldDiagnoseReport
.
ifa_id
==
ifa_id
,
))
periodic_report
=
tamp_diagnose_session
.
query
(
PeriodicReport
)
.
filter
(
and_
(
PeriodicReport
.
id
==
id
,
PeriodicReport
.
ifa_id
==
ifa_id
,
))
if
type
==
1
:
res
=
hold_report
elif
type
==
2
:
res
=
hold_diagnose_report
elif
type
==
3
:
res
=
periodic_report
if
not
res
:
return
False
res
.
update
({
'update_status'
:
1
,
'update_time'
:
datetime
.
datetime
.
now
()
})
try
:
dt
=
DataIntegrate
(
ifa_id
=
ifa_id
,
customer_id
=
res
[
0
]
.
customer_id
,
pdf_name
=
pdf_name
,
type
=
type
)
dt
.
render_data
(
data
=
json
.
loads
(
report_data
.
replace
(
template_folder
,
temp_img_save_folder
)))
except
:
pass
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
hold_report
=
tamp_diagnose_session
.
query
(
HoldReport
)
.
filter
(
and_
(
HoldReport
.
id
==
id
,
HoldReport
.
ifa_id
==
ifa_id
,
))
hold_diagnose_report
=
tamp_diagnose_session
.
query
(
HoldDiagnoseReport
)
.
filter
(
and_
(
HoldDiagnoseReport
.
id
==
id
,
HoldDiagnoseReport
.
ifa_id
==
ifa_id
,
))
periodic_report
=
tamp_diagnose_session
.
query
(
PeriodicReport
)
.
filter
(
and_
(
PeriodicReport
.
id
==
id
,
PeriodicReport
.
ifa_id
==
ifa_id
,
))
if
type
==
1
:
res
=
hold_report
elif
type
==
2
:
res
=
hold_diagnose_report
elif
type
==
3
:
res
=
periodic_report
if
not
res
:
return
False
res
.
update
({
'file'
:
pdf_name
,
'update_status'
:
2
,
'update_time'
:
datetime
.
datetime
.
now
()
})
save_pdf
.
delay
(
ifa_id
,
customer_id
,
pdf_name
,
type
,
report_data
)
# try:
# dt = DataIntegrate(ifa_id=ifa_id, customer_id=res[0].customer_id, pdf_name=pdf_name, type=type)
# dt.render_data(data=json.loads(report_data.replace(template_folder, temp_img_save_folder)))
# except:
# pass
# with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
# tamp_diagnose_session = tamp_diagnose_app.session
# hold_report = tamp_diagnose_session.query(HoldReport).filter(and_(
# HoldReport.id == id,
# HoldReport.ifa_id == ifa_id,
# ))
# hold_diagnose_report = tamp_diagnose_session.query(HoldDiagnoseReport).filter(and_(
# HoldDiagnoseReport.id == id,
# HoldDiagnoseReport.ifa_id == ifa_id,
# ))
# periodic_report = tamp_diagnose_session.query(PeriodicReport).filter(and_(
# PeriodicReport.id == id,
# PeriodicReport.ifa_id == ifa_id,
# ))
# if type == 1:
# res = hold_report
# elif type == 2:
# res = hold_diagnose_report
# elif type == 3:
# res = periodic_report
# if not res:
# return False
# res.update({
# 'file': pdf_name,
# 'update_status': 2,
# 'update_time': datetime.datetime.now()
# })
return
True
...
...
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