A Bun-based worker for processing deal screenings and handling Pub/Sub messages in Google Cloud Run.
- Express.js server with proper error handling
- Redis connection management with retry logic
- Graceful shutdown handling for Cloud Run
- Health check endpoints
- Queue processing for deal screenings
- AI-powered deal evaluation
- Google Cloud SDK installed
- Docker installed
- Redis instance (Cloud Memorystore or external Redis)
Set these environment variables in your Cloud Run service:
REDIS_URL: Redis connection stringNODE_ENV: Set toproductionPORT: Port number (default: 8080)
Before deploying, make sure these secrets are configured in your GitHub repository:
GCP_SA_KEY: Google Cloud Service Account JSON keyREDIS_URL: Redis connection URLDATABASE_URL: Database connection URLAI_API_KEY: AI API key
The service is automatically deployed using GitHub Actions when you push to the main branch.
# Build the Docker image
docker build -t us-central1-docker.pkg.dev/dark-alpha-deal-sourcing/bitrix24/bitrix-worker:latest .
# Push to Artifact Registry
docker push us-central1-docker.pkg.dev/dark-alpha-deal-sourcing/bitrix24/bitrix-worker:latest
# Deploy to Cloud Run
gcloud run deploy bitrix-worker \
--image us-central1-docker.pkg.dev/dark-alpha-deal-sourcing/bitrix24/bitrix-worker:latest \
--region us-central1 \
--memory 2Gi \
--allow-unauthenticatedGET /- Root endpointGET /health- Health check with Redis statusPOST /screen-deal- Process Pub/Sub messages for deal screeningPOST /process-queue- Process Redis queue itemsPOST /file-upload- Handle file uploads
The following fixes have been implemented to resolve 503 errors:
- Graceful Shutdown: Proper handling of SIGTERM/SIGINT signals
- Redis Connection Management: Improved connection handling with retry logic
- Error Boundaries: Comprehensive error handling middleware
- Health Checks: Proper health check endpoints for Cloud Run
- Resource Management: Proper cleanup of connections and resources
- Redis Connection Issues: Ensure
REDIS_URLis properly set and accessible - Memory Issues: Increase memory allocation if processing large deals
- Timeout Issues: Increase timeout settings for long-running operations
# Install dependencies
bun install
# Start development server
bun run start
# Run Prisma commands
bun run prisma:generate
bun run prisma:migrate