af1b8e9956
- Updated Dockerfile to improve security with a non-root user and added health checks. - Modified docker-compose.yml to set containers as read-only, restrict ports to localhost, and implement health checks. - Enhanced .env.example with additional environment variables for security and configuration. - Improved FastAPI application with middleware for security headers, CORS, and body size limits. - Refactored authentication flow in auth.py to include state validation and improved error handling. - Added rate limiting to various endpoints to prevent abuse. - Updated researcher and publication handling to ensure better validation and error management.
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from sqlalchemy.orm import Session
|
|
from app.db.models import SyncJob
|
|
from sqlalchemy.sql import func
|
|
|
|
# ---------------------------------------------------------
|
|
# Repositorio de trabajos de sincronización
|
|
# ---------------------------------------------------------
|
|
|
|
class SyncJobRepository:
|
|
|
|
# ---------------------------------------------------------
|
|
# Función auxiliar: iniciar un nuevo trabajo de sincronización
|
|
# ---------------------------------------------------------
|
|
|
|
@staticmethod
|
|
def start_job(db: Session, researcher_id: str):
|
|
job = SyncJob(
|
|
researcher_id=researcher_id,
|
|
status="running",
|
|
started_at=func.now()
|
|
)
|
|
db.add(job)
|
|
db.commit()
|
|
db.refresh(job)
|
|
return job
|
|
|
|
# ---------------------------------------------------------
|
|
# Función auxiliar: finalizar un trabajo de sincronización
|
|
# ---------------------------------------------------------
|
|
|
|
@staticmethod
|
|
def finish_job(db: Session, job: SyncJob, new_records: int, updated_records: int):
|
|
job.status = "finished"
|
|
job.new_records = new_records
|
|
job.updated_records = updated_records
|
|
job.finished_at = func.now()
|
|
db.commit()
|
|
db.refresh(job)
|
|
return job
|