Endpoint Implementation
The implementation below creates a simple POST endpoint without authentication (for demonstration purposes):This router is mounted at
/events by app/launchpad/api/router.py, so the full path is POST /events/. The body is accepted as a raw dict and validated later by the workflow against CustomerCareEventSchema (the event_schema on CustomerCareWorkflow). This keeps a single endpoint usable for multiple registered workflows.Key Actions Performed
1
Data validation
FastAPI parses the request body as JSON, then stores it. The workflow itself validates against
CustomerCareEventSchema when it runs, raising a validation error if the payload is malformed.2
Database storage
The event is stored with raw JSON, the workflow type from the registry, a generated ID, and timestamps.
3
Task queuing
A Celery task named
process_incoming_event is queued with the event ID and returns a task ID for tracking.4
Response
The endpoint returns HTTP 202 (Accepted) to indicate asynchronous processing.
Understanding the Components
- GenericRepository: Provides database operations (create, read, update, delete) for any model
- db_session: FastAPI dependency that provides a database session for the request
- celery_app: The Celery application instance for queuing background tasks
- WorkflowRegistry: Enum containing all registered workflows in the system