feat: Implementa duas conexões Oracle simultâneas

- Oracle LOCAL (Docker): Para salvar TB_RANKING_CONSULTOR
- Oracle REMOTO (CAPES): Para ler SUCUPIRA_PAINEL.VM_COORDENADOR
- ConsultorRepositoryImpl usa oracle_remote para buscar PPG
- RankingRepository usa oracle_local para salvar ranking
- ProcessarRankingJob recebe ambos os clientes
- Componente B agora está preparado para funcionar

Nota: Elasticsearch precisa ser acessível da rede CAPES
This commit is contained in:
Frederico Castro
2025-12-10 04:21:17 -03:00
parent f69bcd928c
commit e11cdcd083
5 changed files with 70 additions and 15 deletions

View File

@@ -4,17 +4,27 @@ from contextlib import asynccontextmanager
from .routes import router
from .config import settings
from .dependencies import es_client, oracle_client, get_processar_job
from .dependencies import es_client, oracle_local_client, oracle_remote_client, get_processar_job
from ...application.jobs.scheduler import RankingScheduler
@asynccontextmanager
async def lifespan(app: FastAPI):
await es_client.connect()
# Conectar Oracle LOCAL (Docker)
try:
oracle_client.connect()
oracle_local_client.connect()
print("Oracle LOCAL conectado (Docker)")
except Exception as e:
print(f"AVISO: Oracle não conectou: {e}. Sistema rodando sem Coordenação PPG.")
print(f"AVISO: Oracle LOCAL não conectou: {e}")
# Conectar Oracle REMOTO (CAPES)
try:
oracle_remote_client.connect()
print("Oracle REMOTO conectado (CAPES/SUCUPIRA_PAINEL)")
except Exception as e:
print(f"AVISO: Oracle REMOTO não conectou: {e}. Sistema rodando sem Componente B (PPG).")
scheduler = None
try:
@@ -33,8 +43,14 @@ async def lifespan(app: FastAPI):
pass
await es_client.close()
try:
oracle_client.close()
oracle_local_client.close()
except:
pass
try:
oracle_remote_client.close()
except:
pass

View File

@@ -11,9 +11,15 @@ class Settings(BaseSettings):
ES_USER: str = ""
ES_PASSWORD: str = ""
ORACLE_USER: str
ORACLE_PASSWORD: str
ORACLE_DSN: str
# Oracle LOCAL (Docker) - Para salvar ranking
ORACLE_LOCAL_USER: str
ORACLE_LOCAL_PASSWORD: str
ORACLE_LOCAL_DSN: str
# Oracle REMOTO (CAPES) - Para ler SUCUPIRA_PAINEL
ORACLE_REMOTE_USER: str
ORACLE_REMOTE_PASSWORD: str
ORACLE_REMOTE_DSN: str
API_HOST: str = "0.0.0.0"
API_PORT: int = 8000

View File

@@ -13,8 +13,18 @@ es_client = ElasticsearchClient(
password=settings.ES_PASSWORD
)
oracle_client = OracleClient(
user=settings.ORACLE_USER, password=settings.ORACLE_PASSWORD, dsn=settings.ORACLE_DSN
# Oracle LOCAL (Docker) - Para salvar ranking
oracle_local_client = OracleClient(
user=settings.ORACLE_LOCAL_USER,
password=settings.ORACLE_LOCAL_PASSWORD,
dsn=settings.ORACLE_LOCAL_DSN
)
# Oracle REMOTO (CAPES) - Para ler SUCUPIRA_PAINEL
oracle_remote_client = OracleClient(
user=settings.ORACLE_REMOTE_USER,
password=settings.ORACLE_REMOTE_PASSWORD,
dsn=settings.ORACLE_REMOTE_DSN
)
_repository: ConsultorRepositoryImpl = None
@@ -25,14 +35,14 @@ _processar_job: ProcessarRankingJob = None
def get_repository() -> ConsultorRepositoryImpl:
global _repository
if _repository is None:
_repository = ConsultorRepositoryImpl(es_client=es_client, oracle_client=oracle_client)
_repository = ConsultorRepositoryImpl(es_client=es_client, oracle_client=oracle_remote_client)
return _repository
def get_ranking_repository() -> RankingOracleRepository:
global _ranking_repository
if _ranking_repository is None:
_ranking_repository = RankingOracleRepository(oracle_client=oracle_client)
_ranking_repository = RankingOracleRepository(oracle_client=oracle_local_client)
return _ranking_repository
@@ -41,7 +51,8 @@ def get_processar_job() -> ProcessarRankingJob:
if _processar_job is None:
_processar_job = ProcessarRankingJob(
es_client=es_client,
oracle_client=oracle_client,
oracle_remote_client=oracle_remote_client,
oracle_local_client=oracle_local_client,
ranking_repo=get_ranking_repository()
)
return _processar_job