You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,30 @@
1
1
# cronbake
2
2
3
+
## 0.2.0
4
+
5
+
### Minor Changes
6
+
7
+
-**Enhanced Job Control**: Added pause and resume functionality for fine-grained job control
8
+
-**Job Persistence**: Added support for saving and restoring job state across application restarts
9
+
-**Execution Metrics & History**: Comprehensive tracking of job performance including execution counts, success/failure rates, average execution time, and detailed execution history
10
+
-**Priority System**: Jobs can now be assigned priority levels for execution ordering
11
+
-**Advanced Scheduling**: Added two scheduling modes - calculated timeouts (default) for efficiency and traditional polling-based scheduling
12
+
-**Enhanced Error Handling**: Improved error handling with custom error handlers and detailed error tracking
13
+
-**Async Callback Support**: Job callbacks now support both synchronous and asynchronous functions
14
+
-**Job Metrics API**: New methods to access execution history, performance metrics, and reset statistics
15
+
-**Configurable Options**: Enhanced configuration options for polling intervals, history retention, and timeout calculations
16
+
-**Type Safety Improvements**: Enhanced TypeScript definitions for better development experience
17
+
18
+
### Features
19
+
20
+
-**New Job Control Methods**: `pause()`, `resume()`, `getHistory()`, `getMetrics()`, `resetMetrics()`
21
+
-**Persistence Options**: Configurable file-based state persistence with automatic restoration
22
+
-**Job Status Tracking**: Extended status states including 'paused' and 'error' states
23
+
-**Performance Monitoring**: Track total executions, success/failure counts, execution duration, and error details
24
+
-**Priority-based Execution**: Assign and manage job priorities for execution ordering
25
+
-**Enhanced Baker Configuration**: New options for scheduler configuration, persistence settings, and global error handling
26
+
-**Improved Documentation**: Comprehensive README updates with new feature examples and usage patterns
Copy file name to clipboardExpand all lines: README.md
+178-8Lines changed: 178 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,22 +39,64 @@ This a simple graph to show how the cron expression works:
39
39
+------------ second (0 - 59)
40
40
```
41
41
42
+
#### Advanced Scheduling
43
+
44
+
Cronbake provides two scheduling modes for optimal performance:
45
+
46
+
-**Calculated Timeouts** (default): More efficient scheduling using precise timeout calculations
47
+
-**Polling Interval**: Traditional polling-based scheduling with configurable intervals
48
+
42
49
#### Cron Job Management
43
50
44
-
Cronbake provides a simple and intuitive interface for managing cron jobs. You can easily add, remove, start, stop, and destroy cron jobs using the `Baker` class.
51
+
Cronbake provides a simple and intuitive interface for managing cron jobs. You can easily add, remove, start, stop, pause, resume, and destroy cron jobs using the `Baker` class.
52
+
53
+
#### Job Status and Control
54
+
55
+
Cronbake supports comprehensive job control with multiple status states:
56
+
57
+
-**running**: Job is actively executing
58
+
-**stopped**: Job is not executing
59
+
-**paused**: Job is temporarily suspended
60
+
-**error**: Job encountered an error
61
+
62
+
#### Real-time Status and Metrics
63
+
64
+
Cronbake allows you to get the current status, last execution time, next execution time, remaining time, execution history, and comprehensive metrics for each cron job. This information is useful for monitoring, debugging, and performance analysis.
65
+
66
+
#### Execution History and Metrics
67
+
68
+
Track detailed execution history and performance metrics including:
69
+
70
+
- Total executions
71
+
- Successful/failed execution counts
72
+
- Average execution time
73
+
- Execution history with timestamps and durations
74
+
- Error tracking and reporting
75
+
76
+
#### Job Persistence
77
+
78
+
Cronbake supports job persistence across application restarts:
79
+
80
+
- Save job state to file system
81
+
- Automatic restoration on startup
82
+
- Configurable persistence options
45
83
46
-
#### Real-time Status
84
+
#### Callbacks and Error Handling
47
85
48
-
Cronbake allows you to get the current status, last execution time, next execution time, and remaining time for each cron job. This information can be useful for monitoring and debugging purposes.
86
+
With Cronbake, you can execute custom functions when a cron job ticks (runs), completes, or encounters errors. Enhanced error handling provides detailed error information and custom error handlers.
49
87
50
-
#### Callbacks
88
+
#### Priority System
51
89
52
-
With Cronbake, you can execute custom functions when a cron job ticks (runs) or completes. This allows you to perform any necessary actions or side effects related to your cron job.
90
+
Jobs can be assigned priority levels for execution ordering and resource management.
53
91
54
92
#### Type-safe
55
93
56
94
Cronbake is built with TypeScript, ensuring type safety and better tooling support. This helps catch errors during development and provides better code navigation and auto-completion.
57
95
96
+
#### Async Support
97
+
98
+
Full support for asynchronous callbacks and Promise-based operations.
99
+
58
100
### Installation
59
101
60
102
You can install Cronbake using your preferred package manager:
You can manage cron jobs using the various methods provided by the `Baker` class, such as `remove`, `stop`, `destroy`, `getStatus`, `isRunning`, `lastExecution`, `nextExecution`, `remaining`, and `time`.
159
+
#### Advanced Configuration
160
+
161
+
You can configure the Baker with advanced options:
You can manage cron jobs using the various methods provided by the `Baker` class:
216
+
217
+
```typescript
218
+
// Start, stop, pause, and resume jobs
219
+
baker.bake('job-name');
220
+
baker.stop('job-name');
221
+
baker.pause('job-name');
222
+
baker.resume('job-name');
223
+
224
+
// Bulk operations
225
+
baker.bakeAll();
226
+
baker.stopAll();
227
+
baker.pauseAll();
228
+
baker.resumeAll();
229
+
230
+
// Get job information
231
+
const status =baker.getStatus('job-name');
232
+
const isRunning =baker.isRunning('job-name');
233
+
const nextRun =baker.nextExecution('job-name');
234
+
const remaining =baker.remaining('job-name');
235
+
236
+
// Get metrics and history
237
+
const metrics =baker.getMetrics('job-name');
238
+
const history =baker.getHistory('job-name');
239
+
240
+
// Job management
241
+
const jobNames =baker.getJobNames();
242
+
const allJobs =baker.getAllJobs();
243
+
```
244
+
245
+
#### Persistence Operations
246
+
247
+
Save and restore job state:
248
+
249
+
```typescript
250
+
// Save current state
251
+
awaitbaker.saveState();
252
+
253
+
// Restore from saved state
254
+
awaitbaker.restoreState();
255
+
```
256
+
257
+
### Baker Methods
118
258
119
259
| Method | Description |
120
260
| --- | --- |
121
261
|`add(options: CronOptions<T>)`| Adds a new cron job to the baker. |
122
262
|`remove(name: string)`| Removes a cron job from the baker. |
123
263
|`bake(name: string)`| Starts a cron job. |
124
264
|`stop(name: string)`| Stops a cron job. |
265
+
|`pause(name: string)`| Pauses a cron job. |
266
+
|`resume(name: string)`| Resumes a paused cron job. |
125
267
|`destroy(name: string)`| Destroys a cron job. |
126
268
|`getStatus(name: string)`| Returns the status of a cron job. |
127
269
|`isRunning(name: string)`| Checks if a cron job is running. |
128
270
|`lastExecution(name: string)`| Returns the last execution time of a cron job. |
129
271
|`nextExecution(name: string)`| Returns the next execution time of a cron job. |
130
272
|`remaining(name: string)`| Returns the remaining time until the next execution of a cron job. |
131
273
|`time(name: string)`| Returns the current time of a cron job. |
274
+
|`getHistory(name: string)`| Returns the execution history of a cron job. |
275
+
|`getMetrics(name: string)`| Returns the metrics of a cron job. |
276
+
|`getJobNames()`| Returns all cron job names. |
277
+
|`getAllJobs()`| Returns all cron jobs with their status. |
132
278
|`bakeAll()`| Starts all cron jobs. |
133
279
|`stopAll()`| Stops all cron jobs. |
280
+
|`pauseAll()`| Pauses all cron jobs. |
281
+
|`resumeAll()`| Resumes all cron jobs. |
134
282
|`destroyAll()`| Destroys all cron jobs. |
283
+
|`saveState()`| Saves the current state of all jobs to persistence storage. |
284
+
|`restoreState()`| Restores jobs from persistence storage. |
285
+
|`resetAllMetrics()`| Resets metrics for all jobs. |
135
286
|`static create(options: IBakerOptions)`| Creates a new instance of `Baker`. |
136
287
137
-
138
-
#### Advanced Usage
288
+
### Advanced Usage
139
289
140
290
Cronbake also provides a `Cron` class that you can use directly to create and manage individual cron jobs. This can be useful if you need more granular control over cron job instances.
141
291
@@ -155,16 +305,27 @@ const job = Cron.create({
155
305
onComplete: () => {
156
306
console.log('Job completed!');
157
307
},
308
+
onError: (error) => {
309
+
console.error('Job failed:', error.message);
310
+
},
311
+
priority: 10,
158
312
});
159
313
160
314
// Start the cron job
161
315
job.start();
316
+
// Pause the cron job
317
+
job.pause();
318
+
// Resume the cron job
319
+
job.resume();
162
320
// Stop the cron job
163
321
job.stop();
164
322
// Get the job status
165
323
const status =job.getStatus();
166
324
// Get the next execution time
167
325
const nextExecution =job.nextExecution();
326
+
// Get metrics and history
327
+
const metrics =job.getMetrics();
328
+
const history =job.getHistory();
168
329
```
169
330
170
331
Cronbake also provides utility functions for parsing cron expressions, getting the next or previous execution times, and validating cron expressions.
0 commit comments