# โฐ TAT Notifications - Quick Start Guide ## ๐ŸŽฏ Goal Get TAT (Turnaround Time) notifications working in **under 5 minutes**! --- ## โœ… Step 1: Setup Redis (Required) ### ๐Ÿš€ Option A: Upstash (RECOMMENDED - No Installation!) **Best for Windows/Development - 100% Free** 1. **Sign up**: Go to https://console.upstash.com/ 2. **Create Database**: Click "Create Database" - Name: `redis-tat-dev` - Type: Regional - Region: Choose closest to you - Click "Create" 3. **Copy Connection URL**: You'll get a URL like: ``` rediss://default:AbCd1234...@us1-mighty-shark-12345.upstash.io:6379 ``` 4. **Update `.env` in Re_Backend/**: ```bash REDIS_URL=rediss://default:AbCd1234...@us1-mighty-shark-12345.upstash.io:6379 ``` โœ… **Done!** No installation, no setup, works everywhere! --- ### Alternative: Docker (If you prefer local) If you have Docker Desktop: ```bash docker run -d --name redis-tat -p 6379:6379 redis:latest ``` Then in `.env`: ```bash REDIS_URL=redis://localhost:6379 ``` --- ## โšก Step 2: Enable Test Mode (HIGHLY RECOMMENDED) For testing, enable **fast mode** where **1 hour = 1 minute**: ### Edit `.env` file in `Re_Backend/`: ```bash TAT_TEST_MODE=true ``` This means: - โœ… 6-hour TAT = 6 minutes (instead of 6 hours) - โœ… 48-hour TAT = 48 minutes (instead of 48 hours) - โœ… Perfect for quick testing! --- ## ๐Ÿš€ Step 3: Restart Backend ```bash cd Re_Backend npm run dev ``` ### You Should See: ``` โœ… [TAT Queue] Connected to Redis โœ… [TAT Worker] Initialized and listening โฐ TAT Configuration: - Test Mode: ENABLED (1 hour = 1 minute) - Redis: rediss://***@upstash.io:6379 ``` ๐Ÿ’ก If you see connection errors, double-check your `REDIS_URL` in `.env` --- ## ๐Ÿงช Step 4: Test It! ### Create a Request: 1. **Frontend**: Create a new workflow request 2. **Set TAT**: 6 hours (becomes 6 minutes in test mode) 3. **Submit** the request ### Watch the Magic: ``` โœจ At 3 minutes: โณ 50% notification โœจ At 4.5 minutes: โš ๏ธ 75% notification โœจ At 6 minutes: โฐ 100% breach notification ``` ### Check Logs: ```bash # You'll see: [TAT Scheduler] โœ… TAT jobs scheduled for request... [TAT Processor] Processing tat50 for request... [TAT Processor] tat50 notification sent for request... ``` --- ## ๐Ÿ“Š Verify in Database ```sql SELECT approver_name, tat_hours, tat50_alert_sent, tat75_alert_sent, tat_breached, status FROM approval_levels WHERE status = 'IN_PROGRESS'; ``` You should see the flags change as notifications are sent! --- ## โŒ Troubleshooting ### "ECONNREFUSED" or Connection Error? **Problem**: Can't connect to Redis **Solution**: 1. **Check `.env` file**: ```bash # Make sure REDIS_URL is set correctly REDIS_URL=rediss://default:YOUR_PASSWORD@YOUR_URL.upstash.io:6379 ``` 2. **Verify Upstash Database**: - Go to https://console.upstash.com/ - Check database status (should be "Active") - Copy connection URL again if needed 3. **Test Connection**: - Use Upstash's Redis CLI in their console - Or install `redis-cli` and test: ```bash redis-cli -u "rediss://default:YOUR_PASSWORD@YOUR_URL.upstash.io:6379" ping # Should return: PONG ``` ### No Notifications? **Checklist**: - โœ… REDIS_URL set in `.env`? - โœ… Backend restarted after setting REDIS_URL? - โœ… TAT_TEST_MODE=true in `.env`? - โœ… Request submitted (not just created)? - โœ… Logs show "Connected to Redis"? ### Still Issues? ```bash # Check detailed logs Get-Content Re_Backend/logs/app.log -Tail 50 -Wait # Look for: # โœ… [TAT Queue] Connected to Redis # โŒ [TAT Queue] Redis connection error ``` --- ## ๐ŸŽ“ Testing Scenarios ### Quick Test (6 minutes): ``` TAT: 6 hours (6 minutes in test mode) โ”œโ”€ 3 min โณ 50% reminder โ”œโ”€ 4.5 min โš ๏ธ 75% warning โ””โ”€ 6 min โฐ 100% breach ``` ### Medium Test (24 minutes): ``` TAT: 24 hours (24 minutes in test mode) โ”œโ”€ 12 min โณ 50% reminder โ”œโ”€ 18 min โš ๏ธ 75% warning โ””โ”€ 24 min โฐ 100% breach ``` --- ## ๐Ÿ“š More Information - **Full Documentation**: `Re_Backend/docs/TAT_NOTIFICATION_SYSTEM.md` - **Testing Guide**: `Re_Backend/docs/TAT_TESTING_GUIDE.md` - **Redis Setup**: `Re_Backend/INSTALL_REDIS.txt` --- ## ๐ŸŽ‰ Production Mode When ready for production: 1. **Disable Test Mode**: ```bash # In .env TAT_TEST_MODE=false ``` 2. **Restart Backend** 3. **TAT will now use real hours**: - 48-hour TAT = actual 48 hours - Working hours: Mon-Fri, 9 AM - 6 PM --- ## ๐Ÿ†˜ Need Help? Common fixes: ### 1. Verify Upstash Connection ```bash # In Upstash Console (https://console.upstash.com/) # - Click your database # - Use the "CLI" tab to test: PING # - Should return: PONG ``` ### 2. Check Environment Variables ```bash # In Re_Backend/.env, verify: REDIS_URL=rediss://default:YOUR_PASSWORD@YOUR_URL.upstash.io:6379 TAT_TEST_MODE=true ``` ### 3. Clear Redis Queue (if needed) ```bash # In Upstash Console CLI tab: FLUSHALL # This clears all jobs - use only if you need a fresh start ``` ### 4. Restart Backend ```bash cd Re_Backend npm run dev ``` ### 5. Check Logs ```bash Get-Content logs/app.log -Tail 50 -Wait ``` --- **Status Check**: - [ ] Upstash Redis database created - [ ] REDIS_URL copied to `.env` - [ ] TAT_TEST_MODE=true in `.env` - [ ] Backend restarted - [ ] Logs show "TAT Queue: Connected to Redis" - [ ] Test request submitted โœ… All checked? **You're ready!** --- **Last Updated**: November 4, 2025 **Author**: Royal Enfield Workflow Team