Loading
Add email health command
Summary
- Add
bin/cake email_healthwith six checks: Redis, worker heartbeat, queue backlog, Postfix reachability, recent failure rate, mail config - Hard failures exit
1; warnings exit0 - Add unit tests using the email-worker TestableCommand + fake Redis pattern
Check behavior
| Check | PASS | FAIL |
|---|---|---|
| Redis connectivity | PING/PONG OK and cdli:queue:email accessible |
Redis unreachable or queue key inaccessible |
| Worker heartbeat | email:worker:heartbeat age ≤ 2× loop interval |
Missing, invalid, or stale heartbeat |
| Queue backlog | pending+processing ≤ threshold | DB query error |
| Postfix reachability | TCP to host:port succeeds | Connection refused / timeout / DNS failure |
| Recent failure rate | failed jobs in last hour ≤ threshold | DB query error |
| Mail config validity | CDLI_POSTFIX_SMTP_SERVER / USERNAME / PASSWORD set; port valid if present |
Missing/empty vars or invalid port |
Notes
- Env knobs:
EMAIL_HEALTH_BACKLOG_THRESHOLD,EMAIL_HEALTH_FAILURE_THRESHOLD,EMAIL_WORKER_LOOP_INTERVAL(default 6),EMAIL_HEALTH_POSTFIX_HOST/PORT(defaultpostfix:25)
Test plan
-
docker exec -w /srv/app/cake -e CDLI_POSTFIX_SMTP_SERVER=... -e CDLI_POSTFIX_SMTP_USERNAME=... -e CDLI_POSTFIX_SMTP_PASSWORD=... -e CDLI_POSTFIX_SMTP_PORT=587 dev_cake_composer bin/cake email_health - Confirm Redis / backlog / Postfix / failure-rate / mail-config PASS
- Confirm heartbeat FAIL until Redis key is set (or worker heartbeat is added)
-
docker exec -w /srv/app/cake dev_cake_composer vendor/bin/phpunit tests/TestCase/Command/EmailHealthCommandTest.php