7.8 KiB
7.8 KiB
Bus Package Gap Analysis
Overview
This document analyzes the gaps between our Bus package's actual implementation and Laravel's Bus functionality, identifying areas that need implementation or documentation updates.
Related Documentation
- See Bus Package Specification for current implementation
- See Laravel Compatibility Roadmap for overall status
- See Foundation Integration Guide for integration patterns
- See Testing Guide for testing approaches
- See Getting Started Guide for development setup
Implementation Gaps
1. Missing Laravel Features
// Documented but not implemented:
// 1. Job Chaining
class ChainedCommand {
// Need to implement:
void onConnection(String connection);
void onQueue(String queue);
void delay(Duration duration);
void middleware(List<PipeContract> middleware);
}
// 2. Rate Limiting
class RateLimitedCommand {
// Need to implement:
void rateLimit(int maxAttempts, Duration duration);
void rateLimitPerUser(int maxAttempts, Duration duration);
void withoutOverlapping();
}
// 3. Error Handling
class FailedCommandHandler {
// Need to implement:
Future<void> failed(Command command, Exception exception);
Future<void> retry(String commandId);
Future<void> forget(String commandId);
Future<void> flush();
}
2. Existing Features Not Documented
// Implemented but not documented:
// 1. Command Mapping
class CommandMapper {
/// Maps command types to handlers
final Map<Type, Type> _handlers = {};
/// Registers command handler
void map<TCommand extends Command, THandler extends Handler>(
THandler Function() factory
);
}
// 2. Command Context
class CommandContext {
/// Command metadata
final Map<String, dynamic> _metadata = {};
/// Sets command context
void withContext(String key, dynamic value);
/// Gets command context
T? getContext<T>(String key);
}
// 3. Command Lifecycle
class CommandLifecycle {
/// Command hooks
final List<Function> _beforeHandling = [];
final List<Function> _afterHandling = [];
/// Registers lifecycle hooks
void beforeHandling(Function callback);
void afterHandling(Function callback);
}
3. Integration Points Not Documented
// 1. Queue Integration
class QueuedCommand {
/// Queue configuration
String get connection => 'default';
String get queue => 'default';
Duration? get delay => null;
/// Queue callbacks
void onQueue(QueueContract queue);
void onConnection(String connection);
}
// 2. Event Integration
class EventedCommand {
/// Event dispatcher
final EventDispatcherContract _events;
/// Dispatches command events
void dispatchCommandEvent(String event, dynamic data);
void subscribeCommandEvents(EventSubscriber subscriber);
}
// 3. Cache Integration
class CachedCommand {
/// Cache configuration
String get cacheKey => '';
Duration get cacheTTL => Duration(minutes: 60);
/// Cache operations
Future<void> cache();
Future<void> clearCache();
}
Documentation Gaps
1. Missing API Documentation
// Need to document:
/// Maps command types to their handlers.
///
/// Example:
/// ```dart
/// mapper.map<CreateOrder, CreateOrderHandler>(
/// () => CreateOrderHandler(repository)
/// );
/// ```
void map<TCommand extends Command, THandler extends Handler>(
THandler Function() factory
);
/// Sets command execution context.
///
/// Example:
/// ```dart
/// command.withContext('user_id', userId);
/// command.withContext('tenant', tenant);
/// ```
void withContext(String key, dynamic value);
2. Missing Integration Examples
// Need examples for:
// 1. Queue Integration
var command = CreateOrder(...)
..onQueue('orders')
..delay(Duration(minutes: 5));
await bus.dispatch(command);
// 2. Event Integration
class OrderCommand extends EventedCommand {
void handle() {
// Handle command
dispatchCommandEvent('order.handled', order);
}
}
// 3. Cache Integration
class GetOrderCommand extends CachedCommand {
@override
String get cacheKey => 'order.$orderId';
Future<Order> handle() async {
return await cache(() => repository.find(orderId));
}
}
3. Missing Test Coverage
// Need tests for:
void main() {
group('Command Mapping', () {
test('maps commands to handlers', () {
var mapper = CommandMapper();
mapper.map<CreateOrder, CreateOrderHandler>(
() => CreateOrderHandler(repository)
);
var handler = mapper.resolveHandler(CreateOrder());
expect(handler, isA<CreateOrderHandler>());
});
});
group('Command Context', () {
test('handles command context', () {
var command = TestCommand()
..withContext('key', 'value');
expect(command.getContext('key'), equals('value'));
});
});
}
Implementation Priority
-
High Priority
- Command chaining (Laravel compatibility)
- Rate limiting (Laravel compatibility)
- Better error handling
-
Medium Priority
- Command mapping
- Command context
- Performance optimizations
-
Low Priority
- Additional helper methods
- Extended testing utilities
- Debug/profiling tools
Next Steps
-
Implementation Tasks
- Add command chaining
- Add rate limiting
- Add error handling
- Improve queue integration
-
Documentation Tasks
- Document command mapping
- Document command context
- Document command lifecycle
- Add integration examples
-
Testing Tasks
- Add command mapping tests
- Add context tests
- Add lifecycle tests
- Add integration tests
Development Guidelines
1. Getting Started
Before implementing bus features:
- Review Getting Started Guide
- Check Laravel Compatibility Roadmap
- Follow Testing Guide
- Use Foundation Integration Guide
- Review Bus Package Specification
2. Implementation Process
For each bus feature:
- Write tests following Testing Guide
- Implement following Laravel patterns
- Document following Getting Started Guide
- Integrate following Foundation Integration Guide
3. Quality Requirements
All implementations must:
- Pass all tests (see Testing Guide)
- Meet Laravel compatibility requirements
- Follow integration patterns (see Foundation Integration Guide)
- Match specifications in Bus Package Specification
4. Integration Considerations
When implementing bus features:
- Follow patterns in Foundation Integration Guide
- Ensure Laravel compatibility per Laravel Compatibility Roadmap
- Use testing approaches from Testing Guide
- Follow development setup in Getting Started Guide
5. Performance Guidelines
Bus system must:
- Handle high command throughput
- Process chains efficiently
- Support async operations
- Scale horizontally
- Meet performance targets in Laravel Compatibility Roadmap
6. Testing Requirements
Bus tests must:
- Cover all command scenarios
- Test chaining behavior
- Verify rate limiting
- Check error handling
- Follow patterns in Testing Guide
7. Documentation Requirements
Bus documentation must:
- Explain command patterns
- Show chaining examples
- Cover error handling
- Include performance tips
- Follow standards in Getting Started Guide