Implement Notification Center Core with Redis Stream and Worker Architecture
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 17h 7m
- Merged PRs (30d)
- 358
Description
## User Story
As a Backend.AI system administrator, I want a centralized notification processing system that can handle events asynchronously via Redis Stream and process them through worker pools, so that notification delivery is reliable and scalable.
## Context
This story implements the foundational infrastructure for the Notification Center, establishing the event stream, worker architecture, and core processing logic that other components will build upon.
## Functional Requirements
### 1. Redis Stream Management
Implement event stream for notification events:
```python
# Stream configuration
STREAM_KEY = "notification:events"
STREAM_MAXLEN = 500 # Approximate
CONSUMER_GROUP = "notification-workers"
```
**Operations**:
- Event publishing (XADD)
- Consumer group creation
- Message acknowledgment (XACK)
- Stream monitoring
### 2. NotificationEvent Data Model
Define the standardized event object:
```python
@dataclass
class NotificationEvent:
event_id: str
event_type: str # "bgtask.completed", "quota.warning", etc.
timestamp: datetime
source: str # "manager", "agent", "gateway"
# Content
subject: str
body: str | None
severity: Literal["info", "warning", "error", "critical"]
# Structured data for templates
context: dict[str, Any]
metadata: dict[str, Any]
# Optional UI elements
action_url: str | None
actions: list[dict] | None
```
### 3. Worker Pool Implementation
### 4. Event Publisher API
### 5. Handler Registry
### 6. Configuration
## Acceptance Criteria
- [ ] NotificationEvent dataclass with all fields defined
- [ ] Redis Stream operations (XADD, XREADGROUP, XACK)
- [ ] Consumer group auto-creation on startup
- [ ] Worker pool implementation with configurable size
- [ ] Event publisher API with batch support
- [ ] Handler registry with registration/retrieval
- [ ] Configuration in manager.toml
- [ ] Graceful shutdown handling
- [ ] Error isolation and retry logic
- [ ] Unit tests with >80% coverage
## Related Issues
Epic: BA-302
JIRA Issue: BA-2861
Contributor guide
Assessment
This issue has not been assessed yet.