Skip to content

Commit f97033f

Browse files
Merge pull request #2899 from DoronYitz/doronyitz-docs/task-scheduling
docs(task-scheduling): update cron-job method descriptions and fix return types
2 parents 4a74402 + ccf1b07 commit f97033f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

content/techniques/task-scheduling.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,11 @@ The `getCronJob()` method returns the named cron job. The returned `CronJob` obj
252252
- `stop()` - stops a job that is scheduled to run.
253253
- `start()` - restarts a job that has been stopped.
254254
- `setTime(time: CronTime)` - stops a job, sets a new time for it, and then starts it
255-
- `lastDate()` - returns a string representation of the last date a job executed
256-
- `nextDates(count: number)` - returns an array (size `count`) of `moment` objects representing upcoming job execution dates.
255+
- `lastDate()` - returns a `DateTime` representation of the date on which the last execution of a job occurred.
256+
- `nextDate()` - returns a `DateTime` representation of the date when the next execution of a job is scheduled.
257+
- `nextDates(count: number)` - Provides an array (size `count`) of `DateTime` representations for the next set of dates that will trigger job execution. `count` defaults to 0, returning an empty array.
257258

258-
> info **Hint** Use `toDate()` on `moment` objects to render them in human readable form.
259+
> info **Hint** Use `toJSDate()` on `DateTime` objects to render them as a JavaScript Date equivalent to this DateTime.
259260
260261
**Create** a new cron job dynamically using the `SchedulerRegistry#addCronJob` method, as follows:
261262

@@ -295,7 +296,7 @@ getCrons() {
295296
jobs.forEach((value, key, map) => {
296297
let next;
297298
try {
298-
next = value.nextDates().toDate();
299+
next = value.nextDate().toJSDate();
299300
} catch (e) {
300301
next = 'error: next fire date is in the past!';
301302
}
@@ -304,7 +305,7 @@ getCrons() {
304305
}
305306
```
306307

307-
The `getCronJobs()` method returns a `map`. In this code, we iterate over the map and attempt to access the `nextDates()` method of each `CronJob`. In the `CronJob` API, if a job has already fired and has no future firing dates, it throws an exception.
308+
The `getCronJobs()` method returns a `map`. In this code, we iterate over the map and attempt to access the `nextDate()` method of each `CronJob`. In the `CronJob` API, if a job has already fired and has no future firing date, it throws an exception.
308309

309310
#### Dynamic intervals
310311

0 commit comments

Comments
 (0)