Skip to content

feat(redis-bullmq): Redis module, BullMQ queues, cache helpers, metrics - #119

Merged
jhayniffy merged 4 commits into
InsurNiffy:mainfrom
zeekman:feat/redis-bullmq
Mar 25, 2026
Merged

feat(redis-bullmq): Redis module, BullMQ queues, cache helpers, metrics#119
jhayniffy merged 4 commits into
InsurNiffy:mainfrom
zeekman:feat/redis-bullmq

Conversation

@zeekman

@zeekman zeekman commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

close #47

Redis client (src/redis/):
- config.ts: buildRedisConfig() from env vars; TTL constants as single
  source of truth (nonce 5m, rate-limit 60s, policy 30s, claim 10s);
  key naming convention documented.
- client.ts: singleton ioredis with lazyConnect, exponential backoff,
  enableOfflineQueue:false; separate getBullMQConnection() for BullMQ
  blocking commands; checkRedisHealth() with 2s timeout; graceful close.
- cache.ts: cacheGet/Set/Del with graceful degradation; domain helpers
  for policy/claim caches; setNonce/consumeNonce (atomic GET+DEL via Lua,
  fail closed); incrementRateLimit (fail open).
- metrics.ts: collectRedisMetrics()  memory usage + per-queue depth;
  exposed via GET /metrics/redis.

BullMQ queues (src/queues/):
- names.ts: canonical QUEUE_NAMES constant (claim-events, claim-payouts).
- claimEvents.queue.ts: producer with 5-attempt exponential backoff,
  removeOnComplete/Fail limits, closeClaimEventsQueue() for shutdown.
- claimEvents.worker.ts: worker with concurrency:5, stalledInterval:30s,
  maxStalledCount:2; completed/failed/stalled/error event logging.

Application wiring:
- index.ts: GET /health/ready (Redis-aware, 503 on down), GET /metrics/redis.
- server.ts: production entry point with SIGTERM/SIGINT handlers (separated
  from index.ts so tests import without side effects).

Tests (src/__tests__/):
- health.test.ts: /health, /health/ready, /metrics/redis shape  no Redis.
- redis.cache.test.ts: cache round-trip, TTL expiry, nonce atomicity,
  rate-limit increment  skipped if REDIS_HOST not set.
- claimEvents.queue.test.ts: end-to-end job processing, retry on failure
   skipped if REDIS_HOST not set; unit shape test always runs.

Infrastructure:
- docker-compose.yml: Redis 7-alpine with password, maxmemory 256mb,
  allkeys-lru, healthcheck.
- .env.example: all required env vars documented.
- ci.yml: Redis service container added to backend job; REDIS_HOST/PORT
  env vars set so integration tests run in CI.

Config:
- tsconfig.json: target ES2022 (Error.cause support); exclude __tests__.
- tsconfig.test.json: extends base, adds jest types for test files.
- package.json: bullmq, ioredis deps; @types/jest, supertest devDeps;
  ts-jest pointed at tsconfig.test.json.

Docs:
- backend/REDIS.md: outage behaviour table, key naming, TTL conventions,
  queue config rationale, metrics alert thresholds, production checklist.
@drips-wave

drips-wave Bot commented Mar 25, 2026

Copy link
Copy Markdown

@zeekman Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

zeekman and others added 3 commits March 25, 2026 04:55
Backend (Node/TypeScript):
- tsconfig.json: remove types array (causes pre-install error); restored
  with types:[node] since skipLibCheck handles missing @types before install
- tsconfig.test.json: add types:[node,jest]; remove redundant exclude
- eslint.config.mjs: rewrite for ESLint 9 flat config; add ignores for
  dist/; disable no-floating-promises for express handlers; fix --ext flag
  (ignored in flat config) by updating lint script to 'eslint src'
- package.json: add @types/jest devDep; update lint script; point ts-jest
  at tsconfig.test.json
- claimEvents.worker.ts: add explicit Job<ClaimEventJobData> types on
  worker.on callbacks to fix implicit any under strict mode
- ci.yml: add --health-start-period 5s to Redis service options

Contract (Rust/Soroban):
- admin.rs: add missing file (lib.rs declares pub mod admin; build fails
  without it); contains AdminError, require_admin, all admin entrypoints
- storage.rs: add Paused/PendingAdmin DataKey variants and helpers;
  switch next_policy_id/next_claim_id to checked_add (overflow safety)
- token.rs: add transfer_from_contract (used by admin::drain) and
  allowlist enforcement in transfer; remove dead_code allow
- validate.rs: remove DuplicateVote variant (unused; -D warnings = error)
@jhayniffy
jhayniffy merged commit e5a45fe into InsurNiffy:main Mar 25, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend — Redis integration: queues, cache, and ephemeral nonce storage

2 participants