Revert "Corrige pool esgotado e erros do Holmes sem mensagem"
This reverts commit 006687f250.
This commit is contained in:
parent
006687f250
commit
61f16b100b
4 changed files with 76 additions and 115 deletions
|
|
@ -1,7 +1,7 @@
|
|||
from fastapi import APIRouter, HTTPException, status
|
||||
from fastapi.concurrency import run_in_threadpool
|
||||
|
||||
from app.core.database import engine
|
||||
from app.core.database import Conexao
|
||||
from app.utils.holmes import get_holmes_history
|
||||
from app.v1.modules.escrituracao.models.modelo_notas import NotasHolmesInput
|
||||
from app.v1.modules.escrituracao.service import NotasDespesas
|
||||
|
|
@ -10,30 +10,23 @@ escrituracao_router = APIRouter(
|
|||
prefix='/escrituracao'
|
||||
)
|
||||
|
||||
|
||||
def gravar_nota(dados_nota_holmes: NotasHolmesInput, historico: dict | None) -> str:
|
||||
# Pega a conexão só na hora de gravar: segurar ela enquanto espera o Holmes esgotava o pool
|
||||
conexao = engine.raw_connection()
|
||||
try:
|
||||
return NotasDespesas(conexao).inserir_nota_despesas(dados_nota_holmes, historico)
|
||||
finally:
|
||||
conexao.close()
|
||||
|
||||
|
||||
# Rota que recebe a nota do Holmes e grava na PD_HOLMES_APOLLO
|
||||
@escrituracao_router.post(
|
||||
path='/notas_despesas'
|
||||
)
|
||||
async def inserir_nota_despesas(
|
||||
dados_nota_holmes: NotasHolmesInput,
|
||||
conexao: Conexao,
|
||||
):
|
||||
|
||||
# History traz a hora de cada "Aprovar"; se o Holmes falhar, volta None e grava sem a hora do history
|
||||
historico = await get_holmes_history(dados_nota_holmes.id)
|
||||
repo = NotasDespesas(conexao)
|
||||
|
||||
# History traz a hora de cada "Aprovar"; se o Holmes falhar, volta None e grava só Feito / Não Feito
|
||||
historico = await get_holmes_history(dados_nota_holmes.id, conexao)
|
||||
|
||||
try:
|
||||
# O banco é síncrono: roda fora do event loop pra não travar as outras requisições
|
||||
acao = await run_in_threadpool(gravar_nota, dados_nota_holmes, historico)
|
||||
acao = await run_in_threadpool(repo.inserir_nota_despesas, dados_nota_holmes, historico)
|
||||
except ValueError as erro:
|
||||
raise HTTPException(
|
||||
status_code= status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue