Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CSS-Engine-Python-Cusca
Project
Project
Details
Activity
Releases
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
Proyectos-Innovacion-2024
CSS-Engine-Python-Cusca
Commits
016c0749
Commit
016c0749
authored
May 05, 2024
by
Erly Villaroel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Timeout en el script
parent
18e7ce35
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
43 deletions
+39
-43
main.py
app/main/engine/blueprint/main.py
+3
-19
Process.py
app/main/engine/service/Process.py
+32
-22
match-and-exclude-records-actions_v1.py
scripts/match-and-exclude-records-actions_v1.py
+4
-2
No files found.
app/main/engine/blueprint/main.py
View file @
016c0749
...
@@ -6,7 +6,7 @@ from flask import request, jsonify
...
@@ -6,7 +6,7 @@ from flask import request, jsonify
from
config
import
Config
as
cfg
from
config
import
Config
as
cfg
from
app.main.engine.enum.StatusEnum
import
StatusEnum
from
app.main.engine.enum.StatusEnum
import
StatusEnum
from
app.main.engine.service.EngineService
import
EngineService
from
app.main.engine.service.EngineService
import
EngineService
from
wrapt_timeout_decorator
import
*
class
MainController
:
class
MainController
:
...
@@ -33,25 +33,9 @@ class MainController:
...
@@ -33,25 +33,9 @@ class MainController:
try
:
try
:
self
.
executions
+=
1
self
.
executions
+=
1
descriptor
=
request
.
get_json
()
descriptor
=
request
.
get_json
()
tiempo_limite
=
descriptor
[
"config-params"
][
"max-timeout-per-combinations"
]
service
=
EngineService
(
self
.
app
,
descriptor
,
self
.
executions
,
self
.
max_executions
)
response
=
service
.
run
()
@
timeout
(
tiempo_limite
)
def
procesamiento
():
response
=
{}
try
:
response
=
EngineService
(
self
.
app
,
descriptor
,
self
.
executions
,
self
.
max_executions
)
.
run
()
except
Exception
as
e
:
response
[
"statusCode"
]
=
StatusEnum
.
ERROR
.
name
response
[
"error"
]
=
{
"message"
:
""
,
"detail"
:
str
(
e
)}
raise
TimeoutError
(
f
"Tiempo límite de ejecución superado{e}"
)
finally
:
return
response
response
=
procesamiento
()
self
.
app
.
logger
.
info
(
response
)
self
.
app
.
logger
.
info
(
response
)
except
TimeoutError
as
e
:
self
.
app
.
logger
.
error
(
f
"Error al superar timeout. {e}"
)
response
[
"statusCode"
]
=
StatusEnum
.
ERROR
.
name
response
[
"error"
]
=
{
"message"
:
""
,
"detail"
:
str
(
e
)}
except
Exception
as
e
:
except
Exception
as
e
:
self
.
app
.
logger
.
error
(
f
"Error en el envío del parser al servicio. {e}"
)
self
.
app
.
logger
.
error
(
f
"Error en el envío del parser al servicio. {e}"
)
response
[
"statusCode"
]
=
StatusEnum
.
ERROR
.
name
response
[
"statusCode"
]
=
StatusEnum
.
ERROR
.
name
...
...
app/main/engine/service/Process.py
View file @
016c0749
...
@@ -9,13 +9,7 @@ from app.main.engine.util.Utils import Utils
...
@@ -9,13 +9,7 @@ from app.main.engine.util.Utils import Utils
from
app.main.engine.enum.StatusEnum
import
StatusEnum
from
app.main.engine.enum.StatusEnum
import
StatusEnum
from
app.main.engine.enum.CodeResponseEnum
import
CodeResponseEnum
from
app.main.engine.enum.CodeResponseEnum
import
CodeResponseEnum
from
app.main.engine.database.Database
import
Database
from
app.main.engine.database.Database
import
Database
from
wrapt_timeout_decorator
import
*
def
timeout_function
():
raise
TimeoutError
(
"Timeout occurred"
)
class
Process
:
class
Process
:
def
__init__
(
self
,
app
,
descriptor
:
Dict
[
str
,
Any
])
->
None
:
def
__init__
(
self
,
app
,
descriptor
:
Dict
[
str
,
Any
])
->
None
:
self
.
app
=
app
self
.
app
=
app
...
@@ -26,9 +20,6 @@ class Process:
...
@@ -26,9 +20,6 @@ class Process:
def
run
(
self
)
->
Dict
[
str
,
Any
]:
def
run
(
self
)
->
Dict
[
str
,
Any
]:
status
,
status_description
=
StatusEnum
.
OK
,
""
status
,
status_description
=
StatusEnum
.
OK
,
""
input_time
=
self
.
descriptor
[
"config-params"
][
"max-timeout-per-combinations"
]
t
=
Timer
(
input_time
,
timeout_function
)
t
.
start
()
try
:
try
:
# Obteniendo la conexión a la BD
# Obteniendo la conexión a la BD
...
@@ -53,19 +44,39 @@ class Process:
...
@@ -53,19 +44,39 @@ class Process:
obj_script
=
globals
()[
relation
](
self
.
app
)
obj_script
=
globals
()[
relation
](
self
.
app
)
obj_script
.
parser
(
self
.
descriptor
)
obj_script
.
parser
(
self
.
descriptor
)
tiempo_limite
=
obj_script
.
timeout
if
tiempo_limite
is
not
None
:
@
timeout
(
tiempo_limite
)
def
procesamiento
():
try
:
self
.
app
.
logger
.
info
(
f
"Iniciando procesamiento de script"
)
obj_script
.
process
(
source
)
# Guardando resultado
self
.
app
.
logger
.
info
(
f
"Generado y guardando resultado"
)
response
=
obj_script
.
response
()
# response.show()
result
=
self
.
utils
.
create_result
(
response
,
self
.
descriptor
)
save
=
self
.
utils
.
save_result
(
result
,
self
.
descriptor
,
db_session
)
if
save
[
"status"
]
==
StatusEnum
.
ERROR
.
name
:
raise
InterruptedError
(
save
[
"message"
])
# Iniciando process
except
Exception
as
e
:
self
.
app
.
logger
.
info
(
f
"Iniciando procesamiento de script
"
)
raise
TimeoutError
(
f
"Tiempo límite de ejecución superado{e}
"
)
obj_script
.
process
(
source
)
procesamiento
(
)
# Guardando resultado
else
:
self
.
app
.
logger
.
info
(
f
"Generado y guardando resultado"
)
# Iniciando process
response
=
obj_script
.
response
()
self
.
app
.
logger
.
info
(
f
"Iniciando procesamiento de script"
)
# response.show()
obj_script
.
process
(
source
)
result
=
self
.
utils
.
create_result
(
response
,
self
.
descriptor
)
# Guardando resultado
save
=
self
.
utils
.
save_result
(
result
,
self
.
descriptor
,
db_session
)
self
.
app
.
logger
.
info
(
f
"Generado y guardando resultado"
)
if
save
[
"status"
]
==
StatusEnum
.
ERROR
.
name
:
response
=
obj_script
.
response
()
raise
InterruptedError
(
save
[
"message"
])
# response.show()
result
=
self
.
utils
.
create_result
(
response
,
self
.
descriptor
)
save
=
self
.
utils
.
save_result
(
result
,
self
.
descriptor
,
db_session
)
if
save
[
"status"
]
==
StatusEnum
.
ERROR
.
name
:
raise
InterruptedError
(
save
[
"message"
])
except
IndexError
as
e
:
except
IndexError
as
e
:
self
.
app
.
logger
.
error
(
f
"Error extrayendo insumos. Vacío. Error: {e}"
)
self
.
app
.
logger
.
error
(
f
"Error extrayendo insumos. Vacío. Error: {e}"
)
status
,
status_description
=
CodeResponseEnum
.
EMPTY_DATASET
,
str
(
e
)
status
,
status_description
=
CodeResponseEnum
.
EMPTY_DATASET
,
str
(
e
)
...
@@ -92,5 +103,4 @@ class Process:
...
@@ -92,5 +103,4 @@ class Process:
self
.
app
.
logger
.
error
(
f
"Error procesando engine. {e}"
)
self
.
app
.
logger
.
error
(
f
"Error procesando engine. {e}"
)
status
,
status_description
=
StatusEnum
.
ERROR
,
str
(
e
)
status
,
status_description
=
StatusEnum
.
ERROR
,
str
(
e
)
finally
:
finally
:
t
.
cancel
()
return
self
.
utils
.
create_response
(
status
,
status_description
)
return
self
.
utils
.
create_response
(
status
,
status_description
)
scripts/match-and-exclude-records-actions_v1.py
View file @
016c0749
...
@@ -35,12 +35,13 @@ class MatchAndExcludeRecordsAction(ActionInterface):
...
@@ -35,12 +35,13 @@ class MatchAndExcludeRecordsAction(ActionInterface):
def
__init__
(
self
,
app
)
->
None
:
def
__init__
(
self
,
app
)
->
None
:
super
()
.
__init__
(
app
)
super
()
.
__init__
(
app
)
self
.
max_combinations
=
None
self
.
max_combinations
=
None
self
.
timeout
=
None
self
.
comb_per_group
=
None
self
.
comb_per_group
=
None
self
.
exclude_pivot
=
None
self
.
exclude_pivot
=
None
self
.
pivot_params
=
None
self
.
pivot_params
=
None
self
.
ctp_params
=
None
self
.
ctp_params
=
None
self
.
output
=
None
self
.
output
=
None
self
.
config_params
=
[
"max-records-per-combinations"
,
"max-
combinations-per-group
"
,
"exclude-entity-pivot"
]
self
.
config_params
=
[
"max-records-per-combinations"
,
"max-
timeout-per-combinations
"
,
"exclude-entity-pivot"
]
def
parser
(
self
,
descriptor
:
Dict
[
str
,
Any
]):
def
parser
(
self
,
descriptor
:
Dict
[
str
,
Any
]):
# Validar si pyspark y su versión está instalada
# Validar si pyspark y su versión está instalada
...
@@ -76,7 +77,8 @@ class MatchAndExcludeRecordsAction(ActionInterface):
...
@@ -76,7 +77,8 @@ class MatchAndExcludeRecordsAction(ActionInterface):
raise
ReferenceError
(
f
"Parámetro *{param}* no encontrado en pivot o contraparte"
)
raise
ReferenceError
(
f
"Parámetro *{param}* no encontrado en pivot o contraparte"
)
self
.
max_combinations
=
configs
[
"max-records-per-combinations"
]
self
.
max_combinations
=
configs
[
"max-records-per-combinations"
]
self
.
comb_per_group
=
configs
[
"max-combinations-per-group"
]
if
"max-timeout-per-combinations"
in
configs
:
self
.
timeout
=
configs
[
"max-timeout-per-combinations"
]
self
.
exclude_pivot
=
configs
[
"exclude-entity-pivot"
]
self
.
exclude_pivot
=
configs
[
"exclude-entity-pivot"
]
self
.
pivot_params
=
pivot_params
self
.
pivot_params
=
pivot_params
self
.
ctp_params
=
ctp_params
self
.
ctp_params
=
ctp_params
...
...
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