towerops/lib/towerops
Graham McIntire 8ff0c44e7b
Add Redis health checks and improved error handling for Exq
Fixes crashes in Exq.Node.Server when Redis connections fail by adding
health checks before startup and wrapping Exq in a custom supervisor
with better resilience.

Problem:
- Valkey pod restarting frequently (24 times in 28h) due to K8s Flannel CNI issues
- When Redis disconnects, Exq.Node.Server crashes trying to process_signals/2
- Gets nil from Redis instead of expected list, crashes on Enum.each/2
- Rapid crash/restart cycles reduce application stability

Changes:

1. RedisHealthCheck module (lib/towerops/redis_health_check.ex)
   - Waits for Redis availability with exponential backoff before starting Exq
   - Prevents Exq from starting when Redis is unavailable
   - Handles connection errors gracefully without crashing caller processes
   - Supports configurable retry attempts, timeouts, and backoff intervals

2. ExqSupervisor module (lib/towerops/exq_supervisor.ex)
   - Custom supervisor that wraps Exq with health checks
   - Uses one_for_one strategy with limited restarts (3 per 60s)
   - Prevents rapid crash loops when Redis is unstable
   - Increased Exq retry/backoff settings for better Redis recovery
   - Allows application to continue functioning without background jobs if Redis unavailable

3. Updated Application.ex
   - Replaced direct Exq start with ExqSupervisor
   - Removed inline exq_config/0 function (moved to supervisor)

4. Tests
   - Comprehensive tests for RedisHealthCheck (health checks, retries, timeouts)
   - Tests for ExqSupervisor (configuration, restart strategy)
   - All 1006 tests passing

Benefits:
- Prevents Exq crashes from propagating when Redis fails
- Application continues running even when Redis is temporarily unavailable
- Better logging of Redis connection issues
- More graceful degradation during infrastructure problems

Infrastructure Issue (to be addressed separately):
- K8s Flannel CNI plugin failing: /run/flannel/subnet.env not found
- Causing Valkey pod network issues and restarts
- Needs investigation of Flannel daemonset and node configuration

🤖 Generated with Claude Code
2026-01-19 15:38:19 -06:00
..
accounts add user profile settings with name, avatar, and timezone 2026-01-18 10:32:23 -06:00
admin Add superuser system with user impersonation for admin support 2026-01-06 12:50:10 -06:00
agents Add agent rename functionality 2026-01-17 15:48:47 -06:00
alerts moduledocs 2026-01-17 15:08:49 -06:00
api_tokens refactor: use API token auth for profile imports instead of session cookies 2026-01-18 09:30:21 -06:00
devices feat: allow device name to be populated from SNMP sysName 2026-01-17 16:28:43 -06:00
ecto_types improve profile import 2026-01-18 11:46:56 -06:00
mobile_sessions Fix datetime truncation for mobile session schemas 2026-01-15 16:17:05 -06:00
monitoring Fix Credo issues and improve code quality 2026-01-19 15:09:19 -06:00
organizations moduledocs 2026-01-17 15:08:49 -06:00
profiles add universoal import 2026-01-18 16:59:34 -06:00
proto Add ICMP monitoring support to Phoenix agent channel 2026-01-19 13:46:20 -06:00
sites moduledocs 2026-01-17 15:08:49 -06:00
snmp Auto-expand MIB directories to include subdirectories 2026-01-19 14:06:51 -06:00
workers add honeybadger and snmp overhaul 2026-01-18 16:16:08 -06:00
accounts.ex add user profile settings with name, avatar, and timezone 2026-01-18 10:32:23 -06:00
admin.ex rename equipment to device 2026-01-17 14:48:46 -06:00
agents.ex Add agent rename functionality 2026-01-17 15:48:47 -06:00
alerts.ex rename equipment to device 2026-01-17 14:48:46 -06:00
api_tokens.ex fix(imports): handle DateTime microseconds and integer string floats 2026-01-18 11:23:43 -06:00
application.ex Add Redis health checks and improved error handling for Exq 2026-01-19 15:38:19 -06:00
devices.ex Fix Credo issues and improve code quality 2026-01-19 15:09:19 -06:00
exq_supervisor.ex Add Redis health checks and improved error handling for Exq 2026-01-19 15:38:19 -06:00
log_filter.ex Add comprehensive Dialyzer type specifications 2026-01-17 10:52:02 -06:00
mailer.ex moduledocs 2026-01-17 15:08:49 -06:00
mobile_sessions.ex credo cleanup 2026-01-17 15:00:52 -06:00
monitoring.ex feat: add latency graph for ICMP ping monitoring 2026-01-17 16:02:35 -06:00
organizations.ex rename equipment to device 2026-01-17 14:48:46 -06:00
profiles.ex add universoal import 2026-01-18 16:59:34 -06:00
redis_health_check.ex Add Redis health checks and improved error handling for Exq 2026-01-19 15:38:19 -06:00
release.ex fix dialyzer things 2026-01-03 12:56:40 -06:00
repo.ex moduledocs 2026-01-17 15:08:49 -06:00
sites.ex rename equipment to device 2026-01-17 14:48:46 -06:00
snmp.ex more renames 2026-01-17 15:13:56 -06:00