nest-scheduler-engine 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +189 -0
- package/README.md +497 -10
- package/dist/errors/scheduler.errors.d.ts +32 -0
- package/dist/errors/scheduler.errors.js +90 -0
- package/dist/errors/scheduler.errors.js.map +1 -0
- package/dist/interfaces/event-handler.interface.d.ts +1 -0
- package/dist/migrations/002_add_edge_case_fields.d.ts +4 -0
- package/dist/migrations/002_add_edge_case_fields.js +76 -0
- package/dist/migrations/002_add_edge_case_fields.js.map +1 -0
- package/dist/services/dispatcher.service.js +295 -74
- package/dist/services/dispatcher.service.js.map +1 -1
- package/dist/services/event-manager.service.d.ts +1 -0
- package/dist/services/event-manager.service.js +142 -28
- package/dist/services/event-manager.service.js.map +1 -1
- package/dist/services/health-check.service.d.ts +34 -0
- package/dist/services/health-check.service.js +95 -0
- package/dist/services/health-check.service.js.map +1 -0
- package/dist/services/polling-engine.service.d.ts +3 -1
- package/dist/services/polling-engine.service.js +135 -23
- package/dist/services/polling-engine.service.js.map +1 -1
- package/dist/types/inputs.d.ts +1 -0
- package/dist/utils/circuit-breaker.d.ts +16 -0
- package/dist/utils/circuit-breaker.js +62 -0
- package/dist/utils/circuit-breaker.js.map +1 -0
- package/dist/utils/graceful-shutdown.d.ts +15 -0
- package/dist/utils/graceful-shutdown.js +77 -0
- package/dist/utils/graceful-shutdown.js.map +1 -0
- package/dist/utils/logging.d.ts +29 -0
- package/dist/utils/logging.js +69 -0
- package/dist/utils/logging.js.map +1 -0
- package/dist/utils/retry-helper.d.ts +5 -3
- package/dist/utils/retry-helper.js +50 -5
- package/dist/utils/retry-helper.js.map +1 -1
- package/dist/utils/rrule-helper.d.ts +8 -0
- package/dist/utils/rrule-helper.js +116 -3
- package/dist/utils/rrule-helper.js.map +1 -1
- package/dist/utils/security.d.ts +6 -0
- package/dist/utils/security.js +137 -0
- package/dist/utils/security.js.map +1 -0
- package/dist/utils/state-machine.d.ts +13 -0
- package/dist/utils/state-machine.js +89 -0
- package/dist/utils/state-machine.js.map +1 -0
- package/dist/utils/timeout.d.ts +2 -0
- package/dist/utils/timeout.js +43 -0
- package/dist/utils/timeout.js.map +1 -0
- package/dist/utils/validation.d.ts +15 -0
- package/dist/utils/validation.js +215 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +37 -9
- package/dist/tsconfig.tsbuildinfo +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the Scheduler Engine will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [2.0.0] - 2026-04-12
|
|
9
|
+
|
|
10
|
+
### 🎉 Major Release - Production-Grade Features
|
|
11
|
+
|
|
12
|
+
This is a major release with comprehensive production-grade features, fault tolerance, and extensive testing infrastructure.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
#### Production-Grade Error Handling
|
|
17
|
+
- Custom error classes for better error identification and handling
|
|
18
|
+
- `EventNotFoundError`, `HandlerNotFoundError`, `EventTypeNotFoundError`
|
|
19
|
+
- `DatabaseError`, `QueueError`, `InvalidRRuleError`
|
|
20
|
+
- `HandlerTimeoutError`, `MaxRetriesExceededError`
|
|
21
|
+
- All errors include error codes and contextual details for better debugging
|
|
22
|
+
|
|
23
|
+
#### Fault Tolerance & Resilience
|
|
24
|
+
- **Circuit Breaker** pattern implementation for external dependencies
|
|
25
|
+
- Prevents cascading failures
|
|
26
|
+
- Automatic recovery with half-open state
|
|
27
|
+
- Configurable failure threshold and reset timeout
|
|
28
|
+
- **Retry Mechanisms** with intelligent backoff
|
|
29
|
+
- Exponential backoff with configurable cap (max 5 minutes)
|
|
30
|
+
- Jitter support to prevent thundering herd problem
|
|
31
|
+
- Retryable error detection
|
|
32
|
+
- Retry with backoff utility function
|
|
33
|
+
- **Timeout Handling**
|
|
34
|
+
- Handler execution timeout support
|
|
35
|
+
- Configurable timeout per handler
|
|
36
|
+
- Automatic cleanup on timeout
|
|
37
|
+
|
|
38
|
+
#### Monitoring & Observability
|
|
39
|
+
- **Health Check System**
|
|
40
|
+
- Component-level health monitoring (database, queue, polling, dispatcher)
|
|
41
|
+
- Health check API with detailed status
|
|
42
|
+
- Automatic health status updates
|
|
43
|
+
- **Enhanced Logging**
|
|
44
|
+
- Contextual logging with correlation IDs
|
|
45
|
+
- Event lifecycle tracking
|
|
46
|
+
- Performance metrics tracking
|
|
47
|
+
- Structured logging support
|
|
48
|
+
- **Performance Tracking**
|
|
49
|
+
- Duration tracking for operations
|
|
50
|
+
- Mark-based performance measurement
|
|
51
|
+
- Comprehensive metrics export
|
|
52
|
+
|
|
53
|
+
#### Operational Features
|
|
54
|
+
- **Graceful Shutdown Manager**
|
|
55
|
+
- Proper cleanup of resources
|
|
56
|
+
- Registered shutdown handlers
|
|
57
|
+
- Configurable grace period
|
|
58
|
+
- Signal handling (SIGTERM, SIGINT)
|
|
59
|
+
- Uncaught exception/rejection handling
|
|
60
|
+
- **Better Database Operations**
|
|
61
|
+
- Enhanced query polled to include event type names
|
|
62
|
+
- Optimized polling query with JOIN
|
|
63
|
+
- Proper transaction support
|
|
64
|
+
|
|
65
|
+
#### Testing Infrastructure
|
|
66
|
+
- Comprehensive test setup with Jest
|
|
67
|
+
- Test utilities and mock adapters
|
|
68
|
+
- `MockDatabaseAdapter`
|
|
69
|
+
- `MockQueueAdapter`
|
|
70
|
+
- `MockLoggerAdapter`
|
|
71
|
+
- `MockCacheAdapter`
|
|
72
|
+
- Test fixtures for common test data
|
|
73
|
+
- Unit tests for core utilities
|
|
74
|
+
- Error classes (100% coverage)
|
|
75
|
+
- Circuit breaker (100% coverage)
|
|
76
|
+
- Retry helper (96% coverage)
|
|
77
|
+
- Test coverage reporting with thresholds
|
|
78
|
+
- Multiple test modes: unit, integration, e2e
|
|
79
|
+
|
|
80
|
+
### Changed
|
|
81
|
+
|
|
82
|
+
- **Package Version**: Bumped to 2.0.0
|
|
83
|
+
- **Node.js Requirement**: Now requires Node.js >= 18.0.0
|
|
84
|
+
- **Retry Logic**: Enhanced with jitter and capping
|
|
85
|
+
- Fixed delay remains consistent
|
|
86
|
+
- Exponential backoff now caps at 5 minutes
|
|
87
|
+
- Optional jitter (±25%) to prevent synchronized retries
|
|
88
|
+
- **Error Handling**: All errors now use custom error classes
|
|
89
|
+
- **Polling Engine**: Now joins with event_types table to include event names
|
|
90
|
+
- **Event Instance Mapping**: Properly includes eventTypeName field
|
|
91
|
+
|
|
92
|
+
### Fixed
|
|
93
|
+
|
|
94
|
+
- **Database Migration**: Removed non-immutable function `NOW()` from index predicate
|
|
95
|
+
- **Event Type Resolution**: Fixed "No handler for UNKNOWN" error
|
|
96
|
+
- Polling query now properly JOINs with event_types table
|
|
97
|
+
- Event type name correctly propagated through entire lifecycle
|
|
98
|
+
- Recurring events maintain event type name after rescheduling
|
|
99
|
+
- **Logging**: Added debug logging for event dispatching
|
|
100
|
+
|
|
101
|
+
### Development
|
|
102
|
+
|
|
103
|
+
- Added comprehensive testing setup
|
|
104
|
+
- Jest configuration with coverage thresholds
|
|
105
|
+
- Test setup file for global configuration
|
|
106
|
+
- Multiple test script modes in package.json
|
|
107
|
+
- Added development dependencies
|
|
108
|
+
- @nestjs/testing
|
|
109
|
+
- jest, ts-jest
|
|
110
|
+
- @types/jest
|
|
111
|
+
- eslint, prettier
|
|
112
|
+
- @typescript-eslint/parser and plugins
|
|
113
|
+
- Improved build process with type checking
|
|
114
|
+
- Added test:watch mode for development
|
|
115
|
+
|
|
116
|
+
### Documentation
|
|
117
|
+
|
|
118
|
+
- Comprehensive CHANGELOG (this file)
|
|
119
|
+
- Enhanced README with production features
|
|
120
|
+
- Added inline documentation for all new utilities
|
|
121
|
+
- Test examples and patterns
|
|
122
|
+
|
|
123
|
+
### Migration Guide from 1.x to 2.x
|
|
124
|
+
|
|
125
|
+
#### Breaking Changes
|
|
126
|
+
None! Version 2.0.0 is backward compatible with 1.x for the public API.
|
|
127
|
+
|
|
128
|
+
#### New Features to Adopt
|
|
129
|
+
|
|
130
|
+
1. **Enable Health Checks**:
|
|
131
|
+
```typescript
|
|
132
|
+
import { HealthCheckService } from '@your-org/scheduler-engine';
|
|
133
|
+
|
|
134
|
+
// Inject and use in your healthcheck endpoint
|
|
135
|
+
const health = await healthCheckService.check();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
2. **Use Graceful Shutdown**:
|
|
139
|
+
```typescript
|
|
140
|
+
// Graceful shutdown is automatically configured
|
|
141
|
+
// Register custom cleanup handlers if needed
|
|
142
|
+
shutdownManager.registerHandler('custom-cleanup', async () => {
|
|
143
|
+
// Your cleanup code
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
3. **Leverage Circuit Breaker**:
|
|
148
|
+
```typescript
|
|
149
|
+
import { CircuitBreaker } from '@your-org/scheduler-engine';
|
|
150
|
+
|
|
151
|
+
const breaker = new CircuitBreaker(5, 60000, 30000);
|
|
152
|
+
const result = await breaker.execute(() => externalApiCall());
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
4. **Use Custom Errors**:
|
|
156
|
+
```typescript
|
|
157
|
+
import { HandlerNotFoundError } from '@your-org/scheduler-engine';
|
|
158
|
+
|
|
159
|
+
if (!handler) {
|
|
160
|
+
throw new HandlerNotFoundError(eventType);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### Recommended Actions
|
|
165
|
+
|
|
166
|
+
1. Update your database by running migrations again (idempotent)
|
|
167
|
+
2. Install new dev dependencies if developing: `npm install`
|
|
168
|
+
3. Run tests: `npm test`
|
|
169
|
+
4. Review health check endpoint integration
|
|
170
|
+
5. Configure monitoring to track health status
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## [1.0.0] - 2026-04-10
|
|
175
|
+
|
|
176
|
+
### Initial Release
|
|
177
|
+
|
|
178
|
+
- Event-driven scheduling engine for NestJS
|
|
179
|
+
- RRULE support for recurring events
|
|
180
|
+
- Retry logic with exponential backoff
|
|
181
|
+
- Dead-letter queue
|
|
182
|
+
- Database migration support
|
|
183
|
+
- Adapter pattern for resource injection
|
|
184
|
+
- Handler registration with decorators
|
|
185
|
+
- Polling engine and dispatcher
|
|
186
|
+
- Comprehensive documentation and examples
|
|
187
|
+
|
|
188
|
+
[2.0.0]: https://github.com/your-org/scheduler-engine/compare/v1.0.0...v2.0.0
|
|
189
|
+
[1.0.0]: https://github.com/your-org/scheduler-engine/releases/tag/v1.0.0
|