38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
# app/main.py
|
|
|
|
from fastapi import FastAPI
|
|
from api import webhook
|
|
import uvicorn
|
|
from services.webhook_service import scheduler # <-- Importar o scheduler
|
|
|
|
app = FastAPI(
|
|
title="Consultme WhatsApp API",
|
|
description="API para integração com o WhatsApp Cloud API para a Consultme.",
|
|
version="0.0.1",
|
|
)
|
|
|
|
# Inclui as rotas definidas em app/api/webhook.py
|
|
app.include_router(webhook.router)
|
|
|
|
# Rota de teste simples para verificar se a API está no ar (opcional)
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "API do WhatsApp Consultme está rodando!"}
|
|
|
|
# --- Eventos de Startup e Shutdown do FastAPI para o Scheduler ---
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
if not scheduler.running:
|
|
scheduler.start()
|
|
print("INFO: APScheduler iniciado na inicialização da aplicação.")
|
|
|
|
@app.on_event("shutdown")
|
|
async def shutdown_event():
|
|
if scheduler.running:
|
|
scheduler.shutdown()
|
|
print("INFO: APScheduler encerrado no desligamento da aplicação.")
|
|
# --- FIM DOS EVENTOS DO SCHEDULER ---
|
|
|
|
# Exemplo de uso de Uvicorn para rodar o FastAPI
|
|
if __name__ == "__main__":
|
|
uvicorn.run(app, host="0.0.0.0", port=5000) |