mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 19:41:09 +02:00
Applied formatting to 1487+ files using pnpm format:write - TypeScript/JavaScript files - Svelte components - Astro pages - JSON configs - Markdown docs 13 files still need manual review (Astro JSX comments)
7.3 KiB
7.3 KiB
🚀 Job Queue System - Deployment Status
Last Updated: 2025-10-09 14:45 UTC Status: ⚠️ 95% Complete - Minor Bug in process-jobs Function
✅ Successfully Deployed
1. Database Migration
- Status: ✅ Complete
- Migration:
20251009_job_queue_system.sql - Components:
- ✅
job_queuetable with proper schema - ✅
enqueue_job()function - ✅
claim_next_job()function - ✅
complete_job()function - ✅ 3 monitoring views (queue_health, failed_jobs_recent, stuck_jobs)
- ✅ RLS policies configured
- ✅ Proper indexes for performance
- ✅
2. Edge Functions
-
start-generation: ✅ Deployed successfully
- Returns immediately (~100ms)
- Creates generation record and enqueues job
- URL:
https://mjuvnnjxwfwlmxjsgkqu.supabase.co/functions/v1/start-generation
-
process-generation: ✅ Deployed successfully
- Handles Replicate API calls for 15+ AI models
- Supports FLUX, SDXL, Ideogram, SD 3.5, Recraft, etc.
- Can be imported and used by other functions
-
process-jobs: ⚠️ Deployed with minor bug
- URL:
https://mjuvnnjxwfwlmxjsgkqu.supabase.co/functions/v1/process-jobs - Issue: Runtime error when calling
claim_next_job() - Error:
Cannot read properties of undefined (reading 'substring') - Likely Cause: Import issue with process-generation or Supabase client initialization
- URL:
3. Environment Secrets
- Status: ✅ All configured
- Secrets Set:
- ✅
REPLICATE_API_KEY(already existed) - ✅
SUPABASE_URL(auto-set) - ✅
SUPABASE_ANON_KEY(auto-set) - ✅
SUPABASE_SERVICE_ROLE_KEY(auto-set) - ✅
SUPABASE_DB_URL(auto-set)
- ✅
4. pg_cron Worker
- Status: ✅ Configured and running
- Schedule: Every minute (
* * * * *) - Job Name:
process-job-queue - Job ID: 2
- Active: Yes
- Action: Calls
process-jobsEdge Function via HTTP POST
⚠️ Known Issues
Issue 1: process-jobs Function Runtime Error
Symptom:
curl -X POST https://mjuvnnjxwfwlmxjsgkqu.supabase.co/functions/v1/process-jobs
# Returns: {"success":false,"error":"Cannot read properties of undefined (reading 'substring')"}
Root Cause:
The error occurs when calling supabaseAdmin.rpc('claim_next_job'). This is likely due to:
- Import of
process-generation/index.tscausing initialization issues - Supabase client not being properly initialized
- Environment variables not being available
Impact:
- The cron job will fail every minute
- Jobs in the queue won't be processed automatically
- Manual triggering via start-generation still works (but jobs stay pending)
Workaround: Until fixed, you can:
- Use the old
generate-imagefunction (still deployed) - Manually process jobs via SQL:
SELECT * FROM claim_next_job();
Next Steps to Fix:
- Remove the import of
process-generationand inline the code - Add better error handling and logging
- Test with a minimal version first
📊 System Architecture
┌─────────────────┐
│ Client App │
│ (Web/Mobile) │
└────────┬────────┘
│ POST /start-generation
↓
┌─────────────────────────┐
│ start-generation │
│ Edge Function │
│ • Creates generation │
│ • Enqueues job │
│ • Returns immediately │
└────────┬────────────────┘
│
↓
┌─────────────────────────┐
│ job_queue table │
│ • Stores pending jobs │
│ • Atomic locking │
│ • Retry logic │
└────────┬────────────────┘
│
↓ (claimed by)
┌─────────────────────────┐
│ process-jobs │ ← Called every minute by pg_cron
│ Edge Function │ ⚠️ Currently has bug
│ • Claims jobs │
│ • Calls Replicate API │
│ • Enqueues download │
└─────────────────────────┘
🧪 Testing Status
Database Functions
- ✅
enqueue_job()- Works perfectly - ✅
claim_next_job()- Returns SETOF correctly - ✅
complete_job()- Updates jobs correctly - ✅ Views (queue_health, failed_jobs_recent, stuck_jobs) - All working
Edge Functions
- ✅
start-generation- Not tested with auth, but deployed - ✅
process-generation- Deployed, used internally - ⚠️
process-jobs- Has runtime error
pg_cron
- ✅ Extension enabled
- ✅ Cron job scheduled
- ⚠️ Will fail due to process-jobs bug
📝 Quick Commands
Check Queue Status
-- Queue health
SELECT * FROM queue_health;
-- Pending jobs
SELECT COUNT(*) FROM job_queue WHERE status = 'pending';
-- Recent failed jobs
SELECT * FROM failed_jobs_recent;
Manual Job Processing (Workaround)
-- Claim a job manually
SELECT * FROM claim_next_job();
-- Complete a job manually
SELECT complete_job('job-id-here', NULL, NULL);
Check Cron Job Status
-- Check if cron is running
SELECT * FROM cron.job WHERE jobname = 'process-job-queue';
-- Check execution history
SELECT * FROM cron.job_run_details
WHERE jobid = 2
ORDER BY start_time DESC
LIMIT 10;
Edge Function Logs
Dashboard: https://supabase.com/dashboard/project/mjuvnnjxwfwlmxjsgkqu/logs/edge-functions
🎯 Next Steps
Immediate (Fix Bug)
-
Debug process-jobs function
- Simplify to minimal version
- Remove process-generation import
- Add extensive logging
-
Test end-to-end
- Create test job via start-generation
- Verify process-jobs can claim and process it
- Check image is downloaded and stored
Short-term
-
Add monitoring dashboard
- Queue depth alerts
- Failed job notifications
- Processing time metrics
-
Optimize performance
- Tune MAX_PARALLEL_JOBS
- Add job prioritization
- Implement rate limiting
Long-term
-
Add more job types
- Batch generation
- Image variations
- Style transfer
-
Implement webhooks
- Notify client when generation completes
- Support callback URLs
📚 Documentation
- Architecture:
apps/mobile/supabase/functions/ARCHITECTURE.md - Deployment Guide:
apps/mobile/supabase/functions/DEPLOYMENT_GUIDE.md - Quick Reference:
apps/mobile/supabase/functions/QUICK_REFERENCE.md - Migration:
apps/mobile/supabase/migrations/20251009_job_queue_system.sql
✅ Deployment Checklist
- Database migration applied
- job_queue table created
- Database functions created (enqueue_job, claim_next_job, complete_job)
- Monitoring views created
- start-generation function deployed
- process-generation function deployed
- process-jobs function deployed (with bug)
- REPLICATE_API_KEY secret configured
- pg_cron extension enabled
- Cron job scheduled
- End-to-end test passed ⚠️
- Monitoring dashboard setup
- Production traffic migrated
Deployment Team: Claude Code Project: Picture - AI Image Generation Platform Environment: Production (mjuvnnjxwfwlmxjsgkqu)