Skip to content

Commit aef9692

Browse files
committed
chore: release version 0.2.0 with enhanced job control, persistence, metrics tracking, and improved error handling
1 parent 562d6d5 commit aef9692

File tree

10 files changed

+1286
-57
lines changed

10 files changed

+1286
-57
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# cronbake
22

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
27+
328
## 0.1.2
429

530
### Patch Changes

README.md

Lines changed: 178 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,64 @@ This a simple graph to show how the cron expression works:
3939
+------------ second (0 - 59)
4040
```
4141

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+
4249
#### Cron Job Management
4350

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
4583

46-
#### Real-time Status
84+
#### Callbacks and Error Handling
4785

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.
4987

50-
#### Callbacks
88+
#### Priority System
5189

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.
5391

5492
#### Type-safe
5593

5694
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.
5795

96+
#### Async Support
97+
98+
Full support for asynchronous callbacks and Promise-based operations.
99+
58100
### Installation
59101

60102
You can install Cronbake using your preferred package manager:
@@ -114,28 +156,136 @@ const everyMinuteJob = baker.add({
114156
baker.bakeAll();
115157
```
116158

117-
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:
162+
163+
```typescript
164+
import Baker from 'cronbake';
165+
166+
const baker = Baker.create({
167+
autoStart: false,
168+
enableMetrics: true,
169+
schedulerConfig: {
170+
useCalculatedTimeouts: true,
171+
pollingInterval: 1000,
172+
maxHistoryEntries: 100,
173+
},
174+
persistence: {
175+
enabled: true,
176+
filePath: './cronbake-state.json',
177+
autoRestore: true,
178+
},
179+
onError: (error, jobName) => {
180+
console.error(`Job ${jobName} failed:`, error.message);
181+
},
182+
});
183+
```
184+
185+
#### Job Configuration Options
186+
187+
Jobs can be configured with various options:
188+
189+
```typescript
190+
const job = baker.add({
191+
name: 'advanced-job',
192+
cron: '*/30 * * * * *',
193+
callback: async () => {
194+
// Your async job logic here
195+
await processData();
196+
},
197+
onTick: () => {
198+
console.log('Job started');
199+
},
200+
onComplete: () => {
201+
console.log('Job completed');
202+
},
203+
onError: (error) => {
204+
console.error('Job failed:', error.message);
205+
},
206+
priority: 5,
207+
maxHistory: 50,
208+
start: true,
209+
persist: true,
210+
});
211+
```
212+
213+
#### Job Control and Monitoring
214+
215+
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+
await baker.saveState();
252+
253+
// Restore from saved state
254+
await baker.restoreState();
255+
```
256+
257+
### Baker Methods
118258

119259
| Method | Description |
120260
| --- | --- |
121261
| `add(options: CronOptions<T>)` | Adds a new cron job to the baker. |
122262
| `remove(name: string)` | Removes a cron job from the baker. |
123263
| `bake(name: string)` | Starts a cron job. |
124264
| `stop(name: string)` | Stops a cron job. |
265+
| `pause(name: string)` | Pauses a cron job. |
266+
| `resume(name: string)` | Resumes a paused cron job. |
125267
| `destroy(name: string)` | Destroys a cron job. |
126268
| `getStatus(name: string)` | Returns the status of a cron job. |
127269
| `isRunning(name: string)` | Checks if a cron job is running. |
128270
| `lastExecution(name: string)` | Returns the last execution time of a cron job. |
129271
| `nextExecution(name: string)` | Returns the next execution time of a cron job. |
130272
| `remaining(name: string)` | Returns the remaining time until the next execution of a cron job. |
131273
| `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. |
132278
| `bakeAll()` | Starts all cron jobs. |
133279
| `stopAll()` | Stops all cron jobs. |
280+
| `pauseAll()` | Pauses all cron jobs. |
281+
| `resumeAll()` | Resumes all cron jobs. |
134282
| `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. |
135286
| `static create(options: IBakerOptions)` | Creates a new instance of `Baker`. |
136287

137-
138-
#### Advanced Usage
288+
### Advanced Usage
139289

140290
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.
141291

@@ -155,16 +305,27 @@ const job = Cron.create({
155305
onComplete: () => {
156306
console.log('Job completed!');
157307
},
308+
onError: (error) => {
309+
console.error('Job failed:', error.message);
310+
},
311+
priority: 10,
158312
});
159313

160314
// Start the cron job
161315
job.start();
316+
// Pause the cron job
317+
job.pause();
318+
// Resume the cron job
319+
job.resume();
162320
// Stop the cron job
163321
job.stop();
164322
// Get the job status
165323
const status = job.getStatus();
166324
// Get the next execution time
167325
const nextExecution = job.nextExecution();
326+
// Get metrics and history
327+
const metrics = job.getMetrics();
328+
const history = job.getHistory();
168329
```
169330

170331
Cronbake also provides utility functions for parsing cron expressions, getting the next or previous execution times, and validating cron expressions.
@@ -183,12 +344,21 @@ const previousExecution = Cron.getPrevious(cronExpression);
183344
const isValid = Cron.isValid(cronExpression); // true
184345
```
185346

347+
### Cron Methods
348+
186349
| Method | Description |
187350
| --- | --- |
188351
| `start()` | Starts the cron job. |
189352
| `stop()` | Stops the cron job. |
353+
| `pause()` | Pauses the cron job. |
354+
| `resume()` | Resumes the cron job. |
190355
| `getStatus()` | Returns the current status of the cron job. |
356+
| `isRunning()` | Checks if the cron job is running. |
191357
| `nextExecution()` | Returns the date of the next execution of the cron job. |
358+
| `getHistory()` | Returns the execution history of the cron job. |
359+
| `getMetrics()` | Returns the metrics of the cron job. |
360+
| `resetMetrics()` | Resets the metrics and history of the cron job. |
361+
| `static create(options: CronOptions<T>)` | Creates a new cron job with the specified options. |
192362
| `static parse(cron: CronExpressionType<T>)` | Parses the specified cron expression and returns a `CronTime` object. |
193363
| `static getNext(cron: CronExpressionType<T>)` | Gets the next execution time for the specified cron expression. |
194364
| `static getPrevious(cron: CronExpressionType<T>)` | Gets the previous execution time for the specified cron expression. |

bun.lockb

13.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)