Implement EventBus with Redis Pub/Sub #33

Closed
opened 2025-12-29 23:48:23 +00:00 by cardosofelipe · 0 comments

Description

Create centralized event bus for real-time notifications using Redis Pub/Sub.

Requirements

EventBus Class

class EventBus:
    async def publish(self, channel: str, event: Event) -> None
    async def subscribe(self, channels: List[str]) -> AsyncIterator[Event]
    def get_project_channel(self, project_id: UUID) -> str
    def get_agent_channel(self, agent_id: UUID) -> str

Event Types

class EventType(str, Enum):
    # Agent Events
    AGENT_SPAWNED = "agent.spawned"
    AGENT_STATUS_CHANGED = "agent.status_changed"
    AGENT_MESSAGE = "agent.message"
    AGENT_TERMINATED = "agent.terminated"

    # Issue Events
    ISSUE_CREATED = "issue.created"
    ISSUE_UPDATED = "issue.updated"
    ISSUE_ASSIGNED = "issue.assigned"
    ISSUE_CLOSED = "issue.closed"

    # Sprint Events
    SPRINT_STARTED = "sprint.started"
    SPRINT_COMPLETED = "sprint.completed"

    # Approval Events
    APPROVAL_REQUESTED = "approval.requested"
    APPROVAL_GRANTED = "approval.granted"
    APPROVAL_DENIED = "approval.denied"

Event Schema

class Event(BaseModel):
    id: str
    type: EventType
    timestamp: datetime
    project_id: UUID
    actor_id: Optional[UUID]  # Agent or user who triggered
    actor_type: str  # 'agent', 'user', 'system'
    payload: dict

Tests

  • Publish/subscribe cycle
  • Multiple subscribers
  • Channel isolation
  • Event serialization

Acceptance Criteria

  • EventBus class implemented
  • All event types defined
  • Redis Pub/Sub working
  • Project channel isolation
  • Unit tests
  • Integration tests with real Redis

Technical Notes

  • Reference: SPIKE-003 (Real-time communication)
  • Reference: ADR-003 (Redis pub/sub)
  • Use redis.asyncio for async support

Dependencies

  • Depends on: #17 (Redis configuration)

Assignable To

backend-engineer agent

## Description Create centralized event bus for real-time notifications using Redis Pub/Sub. ## Requirements ### EventBus Class ```python class EventBus: async def publish(self, channel: str, event: Event) -> None async def subscribe(self, channels: List[str]) -> AsyncIterator[Event] def get_project_channel(self, project_id: UUID) -> str def get_agent_channel(self, agent_id: UUID) -> str ``` ### Event Types ```python class EventType(str, Enum): # Agent Events AGENT_SPAWNED = "agent.spawned" AGENT_STATUS_CHANGED = "agent.status_changed" AGENT_MESSAGE = "agent.message" AGENT_TERMINATED = "agent.terminated" # Issue Events ISSUE_CREATED = "issue.created" ISSUE_UPDATED = "issue.updated" ISSUE_ASSIGNED = "issue.assigned" ISSUE_CLOSED = "issue.closed" # Sprint Events SPRINT_STARTED = "sprint.started" SPRINT_COMPLETED = "sprint.completed" # Approval Events APPROVAL_REQUESTED = "approval.requested" APPROVAL_GRANTED = "approval.granted" APPROVAL_DENIED = "approval.denied" ``` ### Event Schema ```python class Event(BaseModel): id: str type: EventType timestamp: datetime project_id: UUID actor_id: Optional[UUID] # Agent or user who triggered actor_type: str # 'agent', 'user', 'system' payload: dict ``` ### Tests - Publish/subscribe cycle - Multiple subscribers - Channel isolation - Event serialization ## Acceptance Criteria - [ ] EventBus class implemented - [ ] All event types defined - [ ] Redis Pub/Sub working - [ ] Project channel isolation - [ ] Unit tests - [ ] Integration tests with real Redis ## Technical Notes - Reference: SPIKE-003 (Real-time communication) - Reference: ADR-003 (Redis pub/sub) - Use `redis.asyncio` for async support ## Dependencies - Depends on: #17 (Redis configuration) ## Assignable To backend-engineer agent
cardosofelipe added the backendphase-1 labels 2025-12-29 23:50:16 +00:00
Sign in to join this conversation.