taro-bluetooth-print 2.4.0 → 2.5.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 +41 -0
- package/README.md +10 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/types/adapters/QQAdapter.d.ts +22 -0
- package/dist/types/adapters/ReactNativeAdapter.d.ts +111 -0
- package/dist/types/adapters/index.d.ts +13 -0
- package/dist/types/device/MultiPrinterManager.d.ts +1 -1
- package/dist/types/drivers/StarPrinter.d.ts +243 -0
- package/dist/types/drivers/index.d.ts +1 -0
- package/dist/types/encoding/EncodingService.d.ts +41 -2
- package/dist/types/encoding/index.d.ts +2 -1
- package/dist/types/encoding/korean-japanese.d.ts +127 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/services/BatchPrintManager.d.ts +98 -5
- package/dist/types/services/PrintStatistics.d.ts +189 -0
- package/dist/types/services/ScheduledRetryManager.d.ts +213 -0
- package/dist/types/services/index.d.ts +5 -3
- package/dist/types/utils/image.d.ts +40 -119
- package/dist/types/utils/platform.d.ts +2 -0
- package/package.json +1 -1
- package/src/adapters/AdapterFactory.ts +5 -0
- package/src/adapters/QQAdapter.ts +36 -0
- package/src/adapters/ReactNativeAdapter.ts +517 -0
- package/src/adapters/index.ts +14 -0
- package/src/config/PrinterConfigManager.ts +10 -6
- package/src/device/MultiPrinterManager.ts +10 -10
- package/src/drivers/StarPrinter.ts +555 -0
- package/src/drivers/index.ts +10 -0
- package/src/encoding/EncodingService.ts +261 -4
- package/src/encoding/index.ts +17 -1
- package/src/encoding/korean-japanese.ts +289 -0
- package/src/index.ts +1 -5
- package/src/services/BatchPrintManager.ts +312 -42
- package/src/services/PrintHistory.ts +13 -11
- package/src/services/PrintJobManager.ts +3 -3
- package/src/services/PrintStatistics.ts +504 -0
- package/src/services/PrinterStatus.ts +4 -10
- package/src/services/ScheduledRetryManager.ts +564 -0
- package/src/services/index.ts +38 -3
- package/src/utils/image.ts +476 -342
- package/src/utils/platform.ts +20 -34
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* Batch Print Manager
|
|
3
3
|
*
|
|
4
4
|
* Optimizes printing multiple jobs by:
|
|
5
|
-
* - Merging small jobs
|
|
6
|
-
* - Reducing Bluetooth communication overhead
|
|
5
|
+
* - Merging consecutive small jobs (combining jobs < 50 bytes for efficiency)
|
|
6
|
+
* - Reducing Bluetooth communication overhead via batching
|
|
7
7
|
* - Prioritizing urgent jobs
|
|
8
|
-
* -
|
|
8
|
+
* - Auto-flush on task interval timeout
|
|
9
|
+
* - Batch merge with unified cut commands
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
* ```typescript
|
|
@@ -48,6 +49,12 @@ export interface BatchConfig {
|
|
|
48
49
|
enableMerging: boolean;
|
|
49
50
|
/** Auto-process interval in ms (0 = disabled) */
|
|
50
51
|
autoProcessInterval: number;
|
|
52
|
+
/** Small job size threshold for merging (bytes, default: 50) */
|
|
53
|
+
smallJobThreshold: number;
|
|
54
|
+
/** Interval timeout for auto-flush in ms (0 = disabled) */
|
|
55
|
+
flushIntervalTimeout: number;
|
|
56
|
+
/** Unified cut command appended after batch merge (default: ESC d 4) */
|
|
57
|
+
unifiedCutCommand?: Uint8Array;
|
|
51
58
|
}
|
|
52
59
|
/**
|
|
53
60
|
* Batch statistics
|
|
@@ -61,8 +68,12 @@ export interface BatchStats {
|
|
|
61
68
|
batchesProcessed: number;
|
|
62
69
|
/** Average batch size */
|
|
63
70
|
avgBatchSize: number;
|
|
64
|
-
/** Merged jobs count */
|
|
71
|
+
/** Merged jobs count (small jobs combined) */
|
|
65
72
|
mergedJobs: number;
|
|
73
|
+
/** Auto-flush triggered count */
|
|
74
|
+
autoFlushCount: number;
|
|
75
|
+
/** Unified cuts applied */
|
|
76
|
+
unifiedCutsApplied: number;
|
|
66
77
|
}
|
|
67
78
|
/**
|
|
68
79
|
* Batch events
|
|
@@ -77,12 +88,25 @@ export interface BatchEvents {
|
|
|
77
88
|
'job-rejected': (data: {
|
|
78
89
|
reason: string;
|
|
79
90
|
}) => void;
|
|
91
|
+
'auto-flush': (data: {
|
|
92
|
+
jobCount: number;
|
|
93
|
+
bytes: number;
|
|
94
|
+
}) => void;
|
|
95
|
+
'jobs-merged': (data: {
|
|
96
|
+
fromCount: number;
|
|
97
|
+
toCount: number;
|
|
98
|
+
savedBytes: number;
|
|
99
|
+
}) => void;
|
|
80
100
|
}
|
|
81
101
|
/**
|
|
82
102
|
* Batch Print Manager
|
|
83
103
|
*
|
|
84
104
|
* Collects print jobs and processes them in optimized batches.
|
|
85
|
-
*
|
|
105
|
+
* Features:
|
|
106
|
+
* - Small job merging: consecutive jobs < smallJobThreshold bytes are combined
|
|
107
|
+
* - Interval timeout auto-flush: flushes pending jobs if no new jobs arrive within timeout
|
|
108
|
+
* - Unified cut: optionally appends a single cut command after batch merge
|
|
109
|
+
* - Priority sorting: higher priority jobs are processed first
|
|
86
110
|
*/
|
|
87
111
|
export declare class BatchPrintManager {
|
|
88
112
|
private readonly logger;
|
|
@@ -92,17 +116,30 @@ export declare class BatchPrintManager {
|
|
|
92
116
|
private isProcessing;
|
|
93
117
|
private waitTimer;
|
|
94
118
|
private autoProcessTimer;
|
|
119
|
+
private flushTimer;
|
|
95
120
|
private stats;
|
|
121
|
+
/**
|
|
122
|
+
* Last job timestamp for interval timeout tracking
|
|
123
|
+
*/
|
|
124
|
+
private lastJobAt;
|
|
96
125
|
/**
|
|
97
126
|
* Creates a new BatchPrintManager instance
|
|
127
|
+
*
|
|
128
|
+
* @param config - Optional configuration overrides
|
|
98
129
|
*/
|
|
99
130
|
constructor(config?: Partial<BatchConfig>);
|
|
100
131
|
/**
|
|
101
132
|
* Register event listener
|
|
133
|
+
*
|
|
134
|
+
* @param event - Event name
|
|
135
|
+
* @param callback - Event handler
|
|
102
136
|
*/
|
|
103
137
|
on<K extends keyof BatchEvents>(event: K, callback: BatchEvents[K]): void;
|
|
104
138
|
/**
|
|
105
139
|
* Remove event listener
|
|
140
|
+
*
|
|
141
|
+
* @param event - Event name
|
|
142
|
+
* @param callback - Event handler to remove
|
|
106
143
|
*/
|
|
107
144
|
off<K extends keyof BatchEvents>(event: K, callback: BatchEvents[K]): void;
|
|
108
145
|
/**
|
|
@@ -120,6 +157,9 @@ export declare class BatchPrintManager {
|
|
|
120
157
|
addJob(data: Uint8Array, priority?: number, metadata?: Record<string, unknown>): string;
|
|
121
158
|
/**
|
|
122
159
|
* Add multiple jobs at once
|
|
160
|
+
*
|
|
161
|
+
* @param jobs - Array of job data with optional priority and metadata
|
|
162
|
+
* @returns Array of job IDs
|
|
123
163
|
*/
|
|
124
164
|
addJobs(jobs: Array<{
|
|
125
165
|
data: Uint8Array;
|
|
@@ -128,6 +168,9 @@ export declare class BatchPrintManager {
|
|
|
128
168
|
}>): string[];
|
|
129
169
|
/**
|
|
130
170
|
* Cancel a job by ID
|
|
171
|
+
*
|
|
172
|
+
* @param id - Job ID to cancel
|
|
173
|
+
* @returns true if cancelled, false if not found
|
|
131
174
|
*/
|
|
132
175
|
cancelJob(id: string): boolean;
|
|
133
176
|
/**
|
|
@@ -140,14 +183,20 @@ export declare class BatchPrintManager {
|
|
|
140
183
|
get pendingCount(): number;
|
|
141
184
|
/**
|
|
142
185
|
* Get pending jobs
|
|
186
|
+
*
|
|
187
|
+
* @returns Copy of pending jobs array
|
|
143
188
|
*/
|
|
144
189
|
getPendingJobs(): BatchJob[];
|
|
145
190
|
/**
|
|
146
191
|
* Get current statistics
|
|
192
|
+
*
|
|
193
|
+
* @returns Copy of current stats
|
|
147
194
|
*/
|
|
148
195
|
getStats(): BatchStats;
|
|
149
196
|
/**
|
|
150
197
|
* Update configuration
|
|
198
|
+
*
|
|
199
|
+
* @param updates - Configuration fields to update
|
|
151
200
|
*/
|
|
152
201
|
updateConfig(updates: Partial<BatchConfig>): void;
|
|
153
202
|
/**
|
|
@@ -163,8 +212,41 @@ export declare class BatchPrintManager {
|
|
|
163
212
|
private prepareBatch;
|
|
164
213
|
/**
|
|
165
214
|
* Merge multiple jobs into a single buffer
|
|
215
|
+
*
|
|
216
|
+
* Features:
|
|
217
|
+
* - Consecutive small jobs (< smallJobThreshold bytes) are combined into a single job
|
|
218
|
+
* - Applies unified cut command after all jobs if configured
|
|
219
|
+
*
|
|
220
|
+
* @param jobs - Jobs to merge
|
|
221
|
+
* @returns Merged data with metadata about the merge operation
|
|
166
222
|
*/
|
|
167
223
|
private mergeJobs;
|
|
224
|
+
/**
|
|
225
|
+
* Merge consecutive small jobs (< smallJobThreshold bytes) into combined buffers
|
|
226
|
+
*
|
|
227
|
+
* Small jobs that arrive consecutively are combined to reduce Bluetooth overhead.
|
|
228
|
+
* The merge preserves job boundaries conceptually but sends as a single chunk.
|
|
229
|
+
*
|
|
230
|
+
* @param jobs - Input jobs
|
|
231
|
+
* @returns Jobs after merging consecutive small ones
|
|
232
|
+
*/
|
|
233
|
+
private mergeConsecutiveSmallJobs;
|
|
234
|
+
/**
|
|
235
|
+
* Create a merged job from multiple small buffers
|
|
236
|
+
*
|
|
237
|
+
* @param buffers - Array of small buffers to combine
|
|
238
|
+
* @param priority - Priority of the merged job
|
|
239
|
+
* @param addedAt - Timestamp of the first job in the merge
|
|
240
|
+
* @returns Merged BatchJob
|
|
241
|
+
*/
|
|
242
|
+
private createMergedJob;
|
|
243
|
+
/**
|
|
244
|
+
* Concatenate multiple Uint8Array buffers into one
|
|
245
|
+
*
|
|
246
|
+
* @param buffers - Array of buffers to concatenate
|
|
247
|
+
* @returns Combined buffer
|
|
248
|
+
*/
|
|
249
|
+
private concatBuffers;
|
|
168
250
|
/**
|
|
169
251
|
* Check if we should process immediately
|
|
170
252
|
*/
|
|
@@ -177,6 +259,17 @@ export declare class BatchPrintManager {
|
|
|
177
259
|
* Clear wait timer
|
|
178
260
|
*/
|
|
179
261
|
private clearWaitTimer;
|
|
262
|
+
/**
|
|
263
|
+
* Start the flush timer (interval timeout auto-flush)
|
|
264
|
+
*
|
|
265
|
+
* If no new jobs arrive within flushIntervalTimeout ms, the pending
|
|
266
|
+
* jobs are automatically flushed via the 'auto-flush' event.
|
|
267
|
+
*/
|
|
268
|
+
private startFlushTimer;
|
|
269
|
+
/**
|
|
270
|
+
* Clear flush timer
|
|
271
|
+
*/
|
|
272
|
+
private clearFlushTimer;
|
|
180
273
|
/**
|
|
181
274
|
* Start auto-process timer
|
|
182
275
|
*/
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Print Statistics Service
|
|
3
|
+
*
|
|
4
|
+
* Tracks and aggregates print job statistics including success rates,
|
|
5
|
+
* performance metrics, and breakdowns by date/driver.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const stats = new PrintStatistics();
|
|
10
|
+
* stats.trackJobStart('job-1', { driver: 'EscPos' });
|
|
11
|
+
* stats.trackJobComplete('job-1', 1024, 500);
|
|
12
|
+
* const report = stats.getStatistics();
|
|
13
|
+
* const json = stats.exportToJSON();
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Print statistics data interface (returned by getStatistics)
|
|
18
|
+
*/
|
|
19
|
+
export interface PrintStatisticsData {
|
|
20
|
+
/** Total jobs submitted */
|
|
21
|
+
totalJobs: number;
|
|
22
|
+
/** Successfully completed jobs */
|
|
23
|
+
completedJobs: number;
|
|
24
|
+
/** Failed jobs */
|
|
25
|
+
failedJobs: number;
|
|
26
|
+
/** Cancelled jobs */
|
|
27
|
+
cancelledJobs: number;
|
|
28
|
+
/** Total bytes printed */
|
|
29
|
+
totalBytes: number;
|
|
30
|
+
/** Average print time in milliseconds */
|
|
31
|
+
averagePrintTime: number;
|
|
32
|
+
/** Success rate (0-1) */
|
|
33
|
+
successRate: number;
|
|
34
|
+
/** Breakdown by date (YYYY-MM-DD) */
|
|
35
|
+
byDate: Record<string, {
|
|
36
|
+
completed: number;
|
|
37
|
+
failed: number;
|
|
38
|
+
}>;
|
|
39
|
+
/** Breakdown by driver name */
|
|
40
|
+
byDriver: Record<string, {
|
|
41
|
+
completed: number;
|
|
42
|
+
failed: number;
|
|
43
|
+
}>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Job tracking metadata
|
|
47
|
+
*/
|
|
48
|
+
export interface JobTrackingMeta {
|
|
49
|
+
/** Driver name */
|
|
50
|
+
driver?: string;
|
|
51
|
+
/** Device ID */
|
|
52
|
+
deviceId?: string;
|
|
53
|
+
/** Device name */
|
|
54
|
+
deviceName?: string;
|
|
55
|
+
/** Priority */
|
|
56
|
+
priority?: number;
|
|
57
|
+
/** Additional metadata */
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Internal job record
|
|
62
|
+
*/
|
|
63
|
+
interface JobRecord {
|
|
64
|
+
id: string;
|
|
65
|
+
status: 'started' | 'completed' | 'failed' | 'cancelled';
|
|
66
|
+
startedAt: number;
|
|
67
|
+
completedAt?: number;
|
|
68
|
+
bytes?: number;
|
|
69
|
+
duration?: number;
|
|
70
|
+
error?: string;
|
|
71
|
+
driver?: string;
|
|
72
|
+
deviceId?: string;
|
|
73
|
+
deviceName?: string;
|
|
74
|
+
metadata?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Print Statistics Service
|
|
78
|
+
*
|
|
79
|
+
* Collects and aggregates print job metrics for analytics and monitoring.
|
|
80
|
+
* Provides breakdown by date and driver for detailed reporting.
|
|
81
|
+
*/
|
|
82
|
+
export declare class PrintStatistics {
|
|
83
|
+
private readonly logger;
|
|
84
|
+
/** Internal job records map */
|
|
85
|
+
private readonly jobs;
|
|
86
|
+
/** Statistics counters */
|
|
87
|
+
private totalJobs;
|
|
88
|
+
private completedJobs;
|
|
89
|
+
private failedJobs;
|
|
90
|
+
private cancelledJobs;
|
|
91
|
+
private totalBytes;
|
|
92
|
+
private totalPrintTime;
|
|
93
|
+
/** Date-based breakdown: YYYY-MM-DD -> { completed, failed } */
|
|
94
|
+
private byDate;
|
|
95
|
+
/** Driver-based breakdown: driverName -> { completed, failed } */
|
|
96
|
+
private byDriver;
|
|
97
|
+
/**
|
|
98
|
+
* Track a job start event
|
|
99
|
+
*
|
|
100
|
+
* @param jobId - Unique job identifier
|
|
101
|
+
* @param metadata - Optional job metadata (driver, device info, etc.)
|
|
102
|
+
*/
|
|
103
|
+
trackJobStart(jobId: string, metadata?: JobTrackingMeta): void;
|
|
104
|
+
/**
|
|
105
|
+
* Track a job completion event
|
|
106
|
+
*
|
|
107
|
+
* @param jobId - Unique job identifier
|
|
108
|
+
* @param bytes - Number of bytes printed
|
|
109
|
+
* @param duration - Print duration in milliseconds
|
|
110
|
+
*/
|
|
111
|
+
trackJobComplete(jobId: string, bytes: number, duration: number): void;
|
|
112
|
+
/**
|
|
113
|
+
* Track a job failure event
|
|
114
|
+
*
|
|
115
|
+
* @param jobId - Unique job identifier
|
|
116
|
+
* @param error - Error message or error object
|
|
117
|
+
*/
|
|
118
|
+
trackJobFail(jobId: string, error: unknown): void;
|
|
119
|
+
/**
|
|
120
|
+
* Track a job cancellation event
|
|
121
|
+
*
|
|
122
|
+
* @param jobId - Unique job identifier
|
|
123
|
+
*/
|
|
124
|
+
trackJobCancel(jobId: string): void;
|
|
125
|
+
/**
|
|
126
|
+
* Get current statistics
|
|
127
|
+
*
|
|
128
|
+
* @returns Complete statistics object
|
|
129
|
+
*/
|
|
130
|
+
getStatistics(): PrintStatisticsData;
|
|
131
|
+
/**
|
|
132
|
+
* Export statistics as JSON string
|
|
133
|
+
*
|
|
134
|
+
* @param pretty - Whether to format with indentation (default: true)
|
|
135
|
+
* @returns JSON string representation
|
|
136
|
+
*/
|
|
137
|
+
exportToJSON(pretty?: boolean): string;
|
|
138
|
+
/**
|
|
139
|
+
* Import statistics from JSON string
|
|
140
|
+
*
|
|
141
|
+
* @param json - JSON string to import
|
|
142
|
+
* @returns Number of records imported
|
|
143
|
+
*/
|
|
144
|
+
importFromJSON(json: string): number;
|
|
145
|
+
/**
|
|
146
|
+
* Get statistics for a specific date range
|
|
147
|
+
*
|
|
148
|
+
* @param startDate - Start date (timestamp or Date)
|
|
149
|
+
* @param endDate - End date (timestamp or Date)
|
|
150
|
+
* @returns Filtered statistics
|
|
151
|
+
*/
|
|
152
|
+
getStatisticsByDateRange(startDate: Date | number, endDate: Date | number): PrintStatisticsData;
|
|
153
|
+
/**
|
|
154
|
+
* Get breakdown by date
|
|
155
|
+
*
|
|
156
|
+
* @returns Date-based breakdown object
|
|
157
|
+
*/
|
|
158
|
+
getByDate(): Record<string, {
|
|
159
|
+
completed: number;
|
|
160
|
+
failed: number;
|
|
161
|
+
}>;
|
|
162
|
+
/**
|
|
163
|
+
* Get breakdown by driver
|
|
164
|
+
*
|
|
165
|
+
* @returns Driver-based breakdown object
|
|
166
|
+
*/
|
|
167
|
+
getByDriver(): Record<string, {
|
|
168
|
+
completed: number;
|
|
169
|
+
failed: number;
|
|
170
|
+
}>;
|
|
171
|
+
/**
|
|
172
|
+
* Reset all statistics
|
|
173
|
+
*/
|
|
174
|
+
reset(): void;
|
|
175
|
+
/**
|
|
176
|
+
* Get job record by ID
|
|
177
|
+
*
|
|
178
|
+
* @param jobId - Job identifier
|
|
179
|
+
* @returns Job record or undefined
|
|
180
|
+
*/
|
|
181
|
+
getJobRecord(jobId: string): JobRecord | undefined;
|
|
182
|
+
private formatDateKey;
|
|
183
|
+
private formatError;
|
|
184
|
+
private aggregateByDate;
|
|
185
|
+
private aggregateByDriver;
|
|
186
|
+
}
|
|
187
|
+
/** Singleton instance for convenience */
|
|
188
|
+
export declare const printStatistics: PrintStatistics;
|
|
189
|
+
export {};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { OfflineCache } from '../cache/OfflineCache';
|
|
2
|
+
import { PrintQueue } from '../queue/PrintQueue';
|
|
3
|
+
/**
|
|
4
|
+
* Scheduled retry entry
|
|
5
|
+
*/
|
|
6
|
+
export interface ScheduledRetry {
|
|
7
|
+
/** Job ID to retry */
|
|
8
|
+
jobId: string;
|
|
9
|
+
/** Scheduled execution time */
|
|
10
|
+
runAt: Date;
|
|
11
|
+
/** Current attempt count */
|
|
12
|
+
attemptCount: number;
|
|
13
|
+
/** Maximum retry attempts */
|
|
14
|
+
maxAttempts: number;
|
|
15
|
+
/** Base delay in ms for exponential backoff */
|
|
16
|
+
baseDelay: number;
|
|
17
|
+
/** Maximum delay in ms for exponential backoff */
|
|
18
|
+
maxDelay: number;
|
|
19
|
+
/** Last error message */
|
|
20
|
+
lastError?: string;
|
|
21
|
+
/** Scheduled timeout reference (internal, not serialized) */
|
|
22
|
+
timeout?: ReturnType<typeof setTimeout>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Retry options
|
|
26
|
+
*/
|
|
27
|
+
export interface RetryOptions {
|
|
28
|
+
/** Base delay in ms (default: 1000) */
|
|
29
|
+
baseDelay?: number;
|
|
30
|
+
/** Maximum delay in ms (default: 60000) */
|
|
31
|
+
maxDelay?: number;
|
|
32
|
+
/** Maximum attempts (default: 5) */
|
|
33
|
+
maxAttempts?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Scheduler events
|
|
37
|
+
*/
|
|
38
|
+
export interface ScheduledRetryEvents {
|
|
39
|
+
'retry-due': {
|
|
40
|
+
entry: ScheduledRetry;
|
|
41
|
+
};
|
|
42
|
+
'retry-executed': {
|
|
43
|
+
entry: ScheduledRetry;
|
|
44
|
+
success: boolean;
|
|
45
|
+
};
|
|
46
|
+
'retry-cancelled': {
|
|
47
|
+
jobId: string;
|
|
48
|
+
};
|
|
49
|
+
'retry-exhausted': {
|
|
50
|
+
jobId: string;
|
|
51
|
+
};
|
|
52
|
+
'schedule-restored': {
|
|
53
|
+
count: number;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Event handler type
|
|
58
|
+
*/
|
|
59
|
+
type EventHandler<T> = (data: T) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Scheduled retry configuration
|
|
62
|
+
*/
|
|
63
|
+
export interface ScheduledRetryManagerConfig {
|
|
64
|
+
/** Default base delay in ms */
|
|
65
|
+
baseDelay: number;
|
|
66
|
+
/** Default max delay in ms */
|
|
67
|
+
maxDelay: number;
|
|
68
|
+
/** Default max attempts */
|
|
69
|
+
maxAttempts: number;
|
|
70
|
+
/** Persist scheduled retries to OfflineCache */
|
|
71
|
+
persistEnabled: boolean;
|
|
72
|
+
/** Restore pending retries on startup */
|
|
73
|
+
autoRestore: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Scheduled Retry Manager
|
|
77
|
+
*
|
|
78
|
+
* Manages time-based retries for failed print jobs with support for:
|
|
79
|
+
* - Scheduled execution at specific times
|
|
80
|
+
* - Exponential backoff between retries
|
|
81
|
+
* - Persistence across process restarts via OfflineCache
|
|
82
|
+
* - Event-driven callbacks for retry execution
|
|
83
|
+
*/
|
|
84
|
+
export declare class ScheduledRetryManager {
|
|
85
|
+
private readonly logger;
|
|
86
|
+
/** Scheduled retries map: jobId -> ScheduledRetry */
|
|
87
|
+
private readonly scheduledRetries;
|
|
88
|
+
/** Event listeners */
|
|
89
|
+
private readonly listeners;
|
|
90
|
+
/** Configuration */
|
|
91
|
+
private readonly config;
|
|
92
|
+
/** Offline cache instance for persistence */
|
|
93
|
+
private readonly offlineCache;
|
|
94
|
+
/** Print queue reference for requeueing jobs */
|
|
95
|
+
private printQueue;
|
|
96
|
+
/** Retry executor function */
|
|
97
|
+
private retryExecutor;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new ScheduledRetryManager instance
|
|
100
|
+
*
|
|
101
|
+
* @param config - Optional configuration overrides
|
|
102
|
+
* @param offlineCache - Optional OfflineCache instance (uses singleton if not provided)
|
|
103
|
+
*/
|
|
104
|
+
constructor(config?: Partial<ScheduledRetryManagerConfig>, offlineCache?: OfflineCache);
|
|
105
|
+
/**
|
|
106
|
+
* Set the print queue for job requeuing
|
|
107
|
+
*
|
|
108
|
+
* @param queue - PrintQueue instance
|
|
109
|
+
*/
|
|
110
|
+
setPrintQueue(queue: PrintQueue): void;
|
|
111
|
+
/**
|
|
112
|
+
* Set the retry executor function
|
|
113
|
+
*
|
|
114
|
+
* @param executor - Async function that executes the retry
|
|
115
|
+
*/
|
|
116
|
+
setRetryExecutor(executor: (jobId: string) => Promise<void>): void;
|
|
117
|
+
/**
|
|
118
|
+
* Schedule a retry for a specific job at a given time
|
|
119
|
+
*
|
|
120
|
+
* @param jobId - Job identifier to retry
|
|
121
|
+
* @param runAt - Date/time to execute the retry
|
|
122
|
+
* @param options - Optional retry configuration
|
|
123
|
+
*/
|
|
124
|
+
scheduleRetry(jobId: string, runAt: Date, options?: RetryOptions): void;
|
|
125
|
+
/**
|
|
126
|
+
* Schedule a retry with exponential backoff starting from now
|
|
127
|
+
*
|
|
128
|
+
* @param jobId - Job identifier to retry
|
|
129
|
+
* @param options - Retry options including baseDelay, maxDelay, maxAttempts
|
|
130
|
+
*/
|
|
131
|
+
scheduleRetryWithBackoff(jobId: string, options?: RetryOptions): void;
|
|
132
|
+
/**
|
|
133
|
+
* Cancel a scheduled retry
|
|
134
|
+
*
|
|
135
|
+
* @param jobId - Job identifier to cancel
|
|
136
|
+
* @returns true if a retry was cancelled, false if not found
|
|
137
|
+
*/
|
|
138
|
+
cancelRetry(jobId: string): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Get all scheduled retries
|
|
141
|
+
*
|
|
142
|
+
* @returns Array of scheduled retry entries (without timeout refs)
|
|
143
|
+
*/
|
|
144
|
+
getScheduledRetries(): Array<{
|
|
145
|
+
jobId: string;
|
|
146
|
+
runAt: Date;
|
|
147
|
+
}>;
|
|
148
|
+
/**
|
|
149
|
+
* Get a specific scheduled retry entry
|
|
150
|
+
*
|
|
151
|
+
* @param jobId - Job identifier
|
|
152
|
+
* @returns Scheduled retry entry or undefined
|
|
153
|
+
*/
|
|
154
|
+
getScheduledRetry(jobId: string): ScheduledRetry | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Check if a job has a scheduled retry
|
|
157
|
+
*
|
|
158
|
+
* @param jobId - Job identifier
|
|
159
|
+
* @returns true if retry is scheduled
|
|
160
|
+
*/
|
|
161
|
+
hasScheduledRetry(jobId: string): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Get count of scheduled retries
|
|
164
|
+
*
|
|
165
|
+
* @returns Number of pending scheduled retries
|
|
166
|
+
*/
|
|
167
|
+
get pendingCount(): number;
|
|
168
|
+
/**
|
|
169
|
+
* Register event listener
|
|
170
|
+
*
|
|
171
|
+
* @param event - Event name
|
|
172
|
+
* @param callback - Event handler
|
|
173
|
+
*/
|
|
174
|
+
on<K extends keyof ScheduledRetryEvents>(event: K, callback: EventHandler<ScheduledRetryEvents[K]>): void;
|
|
175
|
+
/**
|
|
176
|
+
* Remove event listener
|
|
177
|
+
*
|
|
178
|
+
* @param event - Event name
|
|
179
|
+
* @param callback - Event handler to remove
|
|
180
|
+
*/
|
|
181
|
+
off<K extends keyof ScheduledRetryEvents>(event: K, callback: EventHandler<ScheduledRetryEvents[K]>): void;
|
|
182
|
+
/**
|
|
183
|
+
* Clear all scheduled retries
|
|
184
|
+
*/
|
|
185
|
+
clearAll(): void;
|
|
186
|
+
/**
|
|
187
|
+
* Destroy the manager
|
|
188
|
+
*/
|
|
189
|
+
destroy(): void;
|
|
190
|
+
/**
|
|
191
|
+
* Execute a scheduled retry
|
|
192
|
+
*/
|
|
193
|
+
private executeRetry;
|
|
194
|
+
/**
|
|
195
|
+
* Persist a scheduled retry to OfflineCache
|
|
196
|
+
*/
|
|
197
|
+
private persistRetry;
|
|
198
|
+
/**
|
|
199
|
+
* Remove a persisted retry from OfflineCache
|
|
200
|
+
*/
|
|
201
|
+
private removePersistedRetry;
|
|
202
|
+
/**
|
|
203
|
+
* Restore scheduled retries from OfflineCache on startup
|
|
204
|
+
*/
|
|
205
|
+
private restoreScheduledRetries;
|
|
206
|
+
/**
|
|
207
|
+
* Emit an event
|
|
208
|
+
*/
|
|
209
|
+
private emit;
|
|
210
|
+
}
|
|
211
|
+
/** Singleton instance */
|
|
212
|
+
export declare const scheduledRetryManager: ScheduledRetryManager;
|
|
213
|
+
export {};
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
export { ConnectionManager, type ConnectionManagerConfig, type ConnectionManagerEvents, } from './ConnectionManager';
|
|
6
6
|
export { CommandBuilder } from './CommandBuilder';
|
|
7
7
|
export { PrintJobManager } from './PrintJobManager';
|
|
8
|
-
export { PrintHistory, printHistory, type PrintHistoryEntry, type PrintHistoryStats, type HistoryQueryOptions } from './PrintHistory';
|
|
9
|
-
export { PrinterStatus, printerStatus, type PrinterStatusInfo, type StatusQueryOptions, type PaperStatus } from './PrinterStatus';
|
|
10
|
-
export { BatchPrintManager, batchPrintManager, type BatchJob, type BatchConfig, type BatchStats, type BatchEvents } from './BatchPrintManager';
|
|
8
|
+
export { PrintHistory, printHistory, type PrintHistoryEntry, type PrintHistoryStats, type HistoryQueryOptions, } from './PrintHistory';
|
|
9
|
+
export { PrinterStatus, printerStatus, type PrinterStatusInfo, type StatusQueryOptions, type PaperStatus, } from './PrinterStatus';
|
|
10
|
+
export { BatchPrintManager, batchPrintManager, type BatchJob, type BatchConfig, type BatchStats, type BatchEvents, } from './BatchPrintManager';
|
|
11
|
+
export { PrintStatistics, printStatistics, type PrintStatisticsData, type JobTrackingMeta, } from './PrintStatistics';
|
|
12
|
+
export { ScheduledRetryManager, scheduledRetryManager, type ScheduledRetry, type RetryOptions, type ScheduledRetryEvents, type ScheduledRetryManagerConfig, } from './ScheduledRetryManager';
|
|
11
13
|
export * from './interfaces';
|