A Python-based SQS consumer service that processes segment mapping jobs and uploads them to the WeBuddhist API.
- AWS SQS consumer for processing manifestation mapping requests
- PostgreSQL database integration for job tracking
- Automatic mapping upload to WeBuddhist API
- Comprehensive logging and error handling
- Python 3.12+
- PostgreSQL database
- AWS account with SQS access
- WeBuddhist API credentials
- Clone the repository:
git clone https://github.com/OpenPecha/sqs-webuddhist-segment-mapping-uploader.git
cd sqs-webuddhist-segment-mapping-uploader- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create a
.envfile in the project root with your configuration:
# Database
POSTGRES_URL=postgresql://user:password@localhost:5432/dbname
# AWS SQS
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
SQS_QUEUE_URL=https://sqs.us-east-1.amazonaws.com/account-id/queue-name
# WeBuddhist API
WEBUDDHIST_API_ENDPOINT=https://api.webuddhist.com
WEBUDDHIST_LOG_IN_EMAIL=your_email@example.com
WEBUDDHIST_LOG_IN_PASSWORD=your_passwordStart the consumer to listen for messages from the SQS queue:
python -m app.mainThe consumer will:
- Listen for messages containing
manifestation_id - Fetch segment mappings from the PostgreSQL database
- Format the payload for WeBuddhist API
- Upload the mappings to WeBuddhist
You can also run the uploader manually for testing:
python -m app.uploaderEnter the manifestation ID when prompted.
.
├── app/
│ ├── config.py # Configuration management
│ ├── main.py # SQS consumer entry point
│ ├── models.py # Pydantic data models
│ ├── uploader.py # Core upload logic
│ └── db/
│ ├── models.py # SQLAlchemy database models
│ └── postgres.py # Database connection setup
├── requirements.txt # Python dependencies
├── .env # Environment variables (not in git)
├── .gitignore # Git ignore rules
└── README.md # This file
The SQS consumer expects messages in the following JSON format:
{
"manifestation_id": "your-manifestation-id-here"
}The application expects the following PostgreSQL tables:
RootJob: Contains job information includingmanifestation_id,job_id,total_segments, andcompleted_segmentsSegmentTask: Contains individual segment tasks withtask_id,job_id,segment_id,status, andresult_json
To verify your AWS SQS configuration:
python test_sqs.pyThis application is designed to be deployed as a Background Worker on Render:
- Push your code to GitHub
- Create a new Background Worker on Render
- Connect your GitHub repository
- Set the start command:
python -m app.main - Add all environment variables from your
.envfile - Create a PostgreSQL database on Render and update
POSTGRES_URL
MIT
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.