# PowerShell script to verify delivery logs are working # Usage: .\test-delivery-logs.ps1 Write-Host "==================================================================" -ForegroundColor Cyan Write-Host " DELIVERY LOG VERIFICATION TEST" -ForegroundColor Cyan Write-Host "==================================================================" -ForegroundColor Cyan Write-Host "" # Configuration $FastAPIUrl = if ($env:FASTAPI_URL) { $env:FASTAPI_URL } else { "https://queue.workolik.com" } $Endpoint = "/live/api/v2/deliveries/createdeliverylog" # Generate unique test data $Timestamp = [int][double]::Parse((Get-Date -UFormat %s)) $OrderId = "TEST-$Timestamp" $CurrentTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss" Write-Host "📋 Test Configuration:" -ForegroundColor Yellow Write-Host " FastAPI URL: $FastAPIUrl" Write-Host " Endpoint: $Endpoint" Write-Host " Test Order ID: $OrderId" Write-Host "" # Test payload $Payload = @( @{ logid = 0 tenantid = 1 partnerid = 44 locationid = 1 orderheaderid = $Timestamp deliveryid = $Timestamp + 1000 userid = 1111 orderid = $OrderId orderstatus = "active" starttime = $CurrentTime logdate = $CurrentTime latitude = "11.0050664" longitude = "76.9508776" } ) | ConvertTo-Json Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "STEP 1: Testing FastAPI Endpoint" -ForegroundColor Cyan Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "" Write-Host "Sending POST request to: $FastAPIUrl$Endpoint" -ForegroundColor Yellow Write-Host "" try { $Response = Invoke-RestMethod -Uri "$FastAPIUrl$Endpoint" ` -Method Post ` -ContentType "application/json" ` -Body $Payload ` -ErrorAction Stop Write-Host "HTTP Status Code: 200" -ForegroundColor Green Write-Host "Response Body:" -ForegroundColor Yellow $Response | ConvertTo-Json -Depth 10 Write-Host "" if ($Response.status -eq "accepted") { Write-Host "✅ SUCCESS: FastAPI accepted the request" -ForegroundColor Green if ($Response.message_id) { Write-Host " Message ID: $($Response.message_id)" -ForegroundColor Green } Write-Host " Status: Accepted" -ForegroundColor Green } else { Write-Host "⚠️ WARNING: Response status is not 'accepted'" -ForegroundColor Yellow } } catch { $StatusCode = $_.Exception.Response.StatusCode.value__ Write-Host "❌ FAILED: FastAPI returned status $StatusCode" -ForegroundColor Red Write-Host "" Write-Host "Error Details:" -ForegroundColor Red Write-Host $_.Exception.Message -ForegroundColor Red Write-Host "" Write-Host "Troubleshooting:" -ForegroundColor Yellow Write-Host "1. Check if FastAPI is running" Write-Host "2. Check FastAPI logs for errors" Write-Host "3. Verify the endpoint URL is correct" exit 1 } Write-Host "" Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "STEP 2: Waiting for Processing" -ForegroundColor Cyan Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "" Write-Host "⏳ Waiting 5 seconds for message to be processed by worker..." -ForegroundColor Yellow Start-Sleep -Seconds 5 Write-Host "" Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "STEP 3: Next Steps for Verification" -ForegroundColor Cyan Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "" Write-Host "To complete verification, check the following:" -ForegroundColor Yellow Write-Host "" Write-Host "1. 📊 NATS Dashboard:" -ForegroundColor Cyan Write-Host " - URL: https://natsadmin.workolik.com" Write-Host " - Login: admin / package@321#" Write-Host " - Check Stream 'EVENTS' → Look for message count" Write-Host " - Check Consumer 'worker_consumer' → Look for pending messages" Write-Host "" Write-Host "2. 📋 Worker Logs:" -ForegroundColor Cyan Write-Host " Docker Compose:" -ForegroundColor Yellow Write-Host " docker-compose logs -f nats-worker | grep deliverylog" Write-Host "" Write-Host " Kubernetes:" -ForegroundColor Yellow Write-Host " kubectl logs -f deployment/nats-worker -n nats-backend | grep deliverylog" Write-Host "" Write-Host " Look for:" -ForegroundColor Yellow Write-Host " ✅ '📨 Processing message for endpoint: /live/api/v2/deliveries/createdeliverylog'" Write-Host " ✅ '➡️ Forwarding createdeliverylog payload: ...'" Write-Host " ✅ '✅ Message processed and forwarded successfully'" Write-Host "" Write-Host "3. 📈 FastAPI Metrics:" -ForegroundColor Cyan Write-Host " curl $FastAPIUrl/metrics | grep deliverylog" Write-Host "" Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "QUICK CHECK COMMANDS" -ForegroundColor Cyan Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "" Write-Host "# Check if workers are running (Docker Compose):" -ForegroundColor Yellow Write-Host "docker-compose ps | grep worker" Write-Host "" Write-Host "# Check if workers are running (Kubernetes):" -ForegroundColor Yellow Write-Host "kubectl get pods -n nats-backend | grep worker" Write-Host "" Write-Host "# View recent worker logs (Docker Compose):" -ForegroundColor Yellow Write-Host "docker-compose logs --tail=50 nats-worker" Write-Host "" Write-Host "# View recent worker logs (Kubernetes):" -ForegroundColor Yellow Write-Host "kubectl logs --tail=50 deployment/nats-worker -n nats-backend" Write-Host "" Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "" Write-Host "✅ Test request sent successfully!" -ForegroundColor Green Write-Host "" Write-Host "Test Order ID: $OrderId" -ForegroundColor Cyan Write-Host "Use this ID to track the message through the system." Write-Host "" Write-Host "For detailed verification steps, see: HOW_TO_VERIFY_DELIVERY_LOGS.txt" -ForegroundColor Yellow