Re_Backend/START_HERE.md

4.4 KiB

🎯 START HERE - TAT Notifications Setup

What You Need to Do RIGHT NOW

2-Minute Setup (Upstash Redis)

  1. Open this link: https://console.upstash.com/

    • Sign up with GitHub/Google (it's free)
  2. Create Redis Database:

    • Click "Create Database"
    • Name: redis-tat-dev
    • Type: Regional
    • Region: Pick closest to you
    • Click "Create"
  3. Copy the Redis URL:

    • You'll see: rediss://default:AbC123xyz...@us1-mighty-12345.upstash.io:6379
    • Click the copy button 📋
  4. Open Re_Backend/.env and add:

    REDIS_URL=rediss://default:AbC123xyz...@us1-mighty-12345.upstash.io:6379
    TAT_TEST_MODE=true
    
  5. Restart Backend:

    cd Re_Backend
    npm run dev
    
  6. Look for this in the logs:

    ✅ [TAT Queue] Connected to Redis
    ✅ [TAT Worker] Initialized and listening
    ⏰ TAT Configuration:
       - Test Mode: ENABLED (1 hour = 1 minute)
    

DONE! You're ready to test!


Test It Now (6 Minutes)

  1. Create a workflow request via your frontend
  2. Set TAT: 6 hours (will become 6 minutes in test mode)
  3. Submit the request
  4. Watch for notifications:
    • 3 minutes: 50% notification
    • 4.5 minutes: ⚠️ 75% warning
    • 6 minutes: 100% breach

Verify It's Working

Check Backend Logs:

# You should see:
[TAT Scheduler] Calculating TAT milestones...
[TAT Scheduler] ✅ TAT jobs scheduled
[TAT Processor] Processing tat50...
[TAT Processor] tat50 notification sent

Check Upstash Console:

  1. Go to https://console.upstash.com/
  2. Click your database
  3. Click "CLI" tab
  4. Type: KEYS bull:tatQueue:*
  5. Should see your scheduled jobs

Check Database:

SELECT 
  approver_name,
  tat50_alert_sent,
  tat75_alert_sent,
  tat_breached,
  status
FROM approval_levels
WHERE status = 'IN_PROGRESS';

What Test Mode Does

Normal Mode:         Test Mode:
48 hours  →          48 minutes
24 hours  →          24 minutes
6 hours   →          6 minutes
2 hours   →          2 minutes

✅ Perfect for quick testing!
✅ Turn off for production: TAT_TEST_MODE=false

Troubleshooting

"ECONNREFUSED" Error?

Fix:

  1. Check your .env file has REDIS_URL=rediss://...
  2. Verify the URL is correct (copy from Upstash again)
  3. Make sure it starts with rediss:// (double 's')
  4. Restart backend: npm run dev

No Logs About Redis?

Fix:

  1. Check .env file exists in Re_Backend/ folder
  2. Make sure you restarted the backend
  3. Look for any errors in console

Jobs Not Running?

Fix:

  1. Verify TAT_TEST_MODE=true in .env
  2. Make sure request is SUBMITTED (not just created)
  3. Check Upstash Console → Metrics (see if commands are running)

Next Steps

Once you see the first notification working:

  1. Test multi-level approvals
  2. Test early approval (jobs should cancel)
  3. Test rejection flow
  4. Check activity logs
  5. Verify database flags

Documentation

  • Quick Start: TAT_QUICK_START.md
  • Upstash Guide: docs/UPSTASH_SETUP_GUIDE.md
  • Full System Docs: docs/TAT_NOTIFICATION_SYSTEM.md
  • Testing Guide: docs/TAT_TESTING_GUIDE.md
  • Quick Reference: UPSTASH_QUICK_REFERENCE.md

Why Upstash?

No installation (works on Windows immediately)
100% free for development
Same setup for production
No maintenance required
Fast (global CDN)
Secure (TLS by default)


Production Deployment

When ready for production:

  1. Keep using Upstash OR install Redis on Linux server:

    sudo apt install redis-server -y
    
  2. Update .env on server:

    REDIS_URL=redis://localhost:6379  # or keep Upstash URL
    TAT_TEST_MODE=false  # Use real hours
    
  3. Deploy and monitor!


Need Help?

Upstash Console: https://console.upstash.com/
Our Docs: See docs/ folder
Redis Commands: Use Upstash Console CLI tab


Status Checklist

  • Upstash account created
  • Redis database created
  • REDIS_URL copied to .env
  • TAT_TEST_MODE=true set
  • Backend restarted
  • Logs show "Connected to Redis"
  • Test request created and submitted
  • First notification received

All done? Congratulations! 🎉

Your TAT notification system is now LIVE!


Last Updated: November 4, 2025
Team: Royal Enfield Workflow