mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-02 14:56:38 +08:00
3.9 KiB
3.9 KiB
Zero-Redis Pluggable Architecture Implementation Plan
Goal: Extract Redis into optional plugins and introduce lightweight in-process equivalents (
cache_memory,driver_inproc_worker,driver_inproc_cron), enabling zero-Redis monolithic and embedded deployment modes.
- Architecture Spec:
docs/superpowers/specs/2026-08-28-zero-redis-pluggable-architecture-design.md - Branch:
main
Proposed Changes
1. In-Memory Cache Infrastructure Plugin (backend/plugins/infra/cache_memory)
[NEW] backend/plugins/infra/cache_memory/plugin.go
- Implements
core.Plugin(Name() == "cache_memory"). - Applies
contracts.CacheServiceto the Context viacore.Provide[contracts.CacheService](ctx, memCacheSvc).
[NEW] backend/plugins/infra/cache_memory/cache.go
- Implements
contracts.CacheServiceusingpkg/cache/ram. - Dispatches in-process invalidation notifications via
ctx.Events().Emit("cache:invalidate", key).
[NEW] backend/plugins/infra/cache_memory/plugin_test.go
- Unit tests for Get, Set, Delete, GetOrSet, TTL expiration, and event bus emission.
2. In-Process Async Worker Driver (backend/plugins/drivers/driver_inproc_worker)
[NEW] backend/plugins/drivers/driver_inproc_worker/plugin.go
- Implements
core.Plugin&core.Driver(Type() == core.DriverTypeWorker). - Scans and executes registered tasks from
ctx.Tasks().Tasks().
[NEW] backend/plugins/drivers/driver_inproc_worker/executor.go
- In-memory buffered channel queue and worker goroutine pool managed via
util.Go. - Supports execution timeout, retry with backoff, and graceful shutdown.
[NEW] backend/plugins/drivers/driver_inproc_worker/plugin_test.go
- Unit tests for in-process task execution, concurrency limit, retry on error, and graceful shutdown.
3. In-Process Cron Scheduler Driver (backend/plugins/drivers/driver_inproc_cron)
[NEW] backend/plugins/drivers/driver_inproc_cron/plugin.go
- Implements
core.Plugin&core.Driver(Type() == core.DriverTypeScheduler). - Reads
ctx.Schedules().Schedules()and schedules jobs usingrobfig/cron/v3.
[NEW] backend/plugins/drivers/driver_inproc_cron/scheduler.go
- Handles Cron expression registration, job triggering, and graceful stopping.
[NEW] backend/plugins/drivers/driver_inproc_cron/plugin_test.go
- Unit tests verifying cron job scheduling, execution tracking, and stop behavior.
4. Admin Domain Decoupling from Redis
[MODIFY] backend/plugins/domain/admin/repository.go
- Introduce in-memory
RingBufferfor task output streams when Redis is nil. - Fallback task log lookups to
RingBufferandw_task_executionstable.
[MODIFY] backend/plugins/domain/admin/system_config_cache.go
- Guard Redis PubSub listener so that when Redis is nil, it gracefully falls back to local event bus updates without spawning disconnected subscriber loops.
5. Application Assembly & Profile Switching
[MODIFY] backend/cmd/app.go
- Switch dynamically between Redis plugins (
cache,driver_asynq_worker,driver_asynq_cron) and In-Process plugins (cache_memory,driver_inproc_worker,driver_inproc_cron) based onconfig.Config.Redis.Enabled.
[MODIFY] backend/cmd/app_test.go
- Add test verifying application bootstrap in both
Redis.Enabled = trueandRedis.Enabled = falsestates.
Verification Plan
Automated Tests
- In-Memory Cache Tests:
go test -v ./backend/plugins/infra/cache_memory/... - In-Process Worker Tests:
go test -v ./backend/plugins/drivers/driver_inproc_worker/... - In-Process Cron Tests:
go test -v ./backend/plugins/drivers/driver_inproc_cron/... - Full Test Suite:
cd backend && go test ./... - Quality Gate:
make code-check && make format