Phase 2: Queue Management ✅ COMPLETED¶
Goal: Implement core business logic for queue operations.
Status: ✅ Completed on 2026-01-19 (Commit: 52eac4c)
Tasks¶
- PulseQueue Class (
src/reeve/pulse/queue.py) ✅ - Implemented async SQLAlchemy session management
- Implemented all methods:
schedule_pulse()- Create new pulseget_due_pulses()- Query pending pulses with priority orderingget_upcoming_pulses()- List future pulsesget_pulse()- Retrieve pulse by IDmark_processing()- Transition to processingmark_completed()- Mark successmark_failed()- Handle failures + retry logic with exponential backoffcancel_pulse()- Cancel pendingreschedule_pulse()- Change timeinitialize()- Initialize database schemaclose()- Clean up resources
-
Priority ordering using SQLAlchemy CASE statement
-
Unit Tests (
tests/test_pulse_queue.py) ✅ - Test database:
sqlite+aiosqlite:///:memory: -
29 comprehensive unit tests covering:
- All CRUD operations
- Priority ordering (CRITICAL → HIGH → NORMAL → LOW → DEFERRED)
- Time-based FIFO within same priority
- Retry logic with exponential backoff (2^retry_count minutes)
- Concurrent operations
- Edge cases (nonexistent pulses, invalid states, etc.)
- Timezone awareness
-
Configuration (
src/reeve/utils/config.py) ✅ - Implemented
ReeveConfigclass with environment variable support - Path expansion for
~and$VAR - Database URL handling (async and sync modes)
-
Singleton pattern with
get_config()andreload_config() -
Enhanced Database Models (
src/reeve/pulse/models.py) ✅ - Added
TZDateTimecustom type for proper timezone handling with SQLite - Updated to SQLAlchemy 2.0 style (
orm.declarative_base) -
All datetime fields preserve timezone information
-
Validation Tests (
tests/test_phase2_validation.py) ✅ - Integration test from roadmap validation example
- End-to-end workflow validation
Deliverables¶
- ✅ Fully functional
PulseQueueclass - ✅ 100% test coverage for queue operations (33/33 tests passed)
- ✅ Configuration management
- ✅ Timezone-aware datetime handling
- ✅ Code formatted with black and isort
Validation¶
# All tests passing
uv run pytest tests/ -v
# Result: 33 passed (3 Phase 1 + 1 Phase 2 integration + 29 Phase 2 unit tests)
Demo¶
Queue Operations:
# Run the demo script
uv run python demos/phase2_queue_demo.py
# Expected output:
# ✓ Initialized PulseQueue
# ✓ Scheduled pulse #1: "High priority task" (due in 5 seconds, priority: HIGH)
# ✓ Scheduled pulse #2: "Normal maintenance" (due in 10 seconds, priority: NORMAL)
# ✓ Scheduled pulse #3: "Low priority cleanup" (due in 15 seconds, priority: LOW)
#
# Upcoming pulses (3):
# 🔔 #1 - HIGH - in 5s - "High priority task"
# ⏰ #2 - NORMAL - in 10s - "Normal maintenance"
# 📋 #3 - LOW - in 15s - "Low priority cleanup"
#
# ✓ Marked pulse #1 as PROCESSING
# ✓ Marked pulse #1 as COMPLETED
#
# ✓ Simulating failure for pulse #2...
# ✓ Marked pulse #2 as FAILED (retry_count=1, will retry in 2 minutes)
#
# ✓ Cancelled pulse #3
#
# Final status:
# - Pulse #1: COMPLETED ✅
# - Pulse #2: PENDING (scheduled for retry in ~2 minutes) 🔄
# - Pulse #3: CANCELLED ❌
#
# ✓ Phase 2 Demo Complete!
Previous: Phase 1: Foundation
Next: Phase 3: MCP Servers