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: content/techniques/task-scheduling.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -252,10 +252,11 @@ The `getCronJob()` method returns the named cron job. The returned `CronJob` obj
252
252
-`stop()` - stops a job that is scheduled to run.
253
253
-`start()` - restarts a job that has been stopped.
254
254
-`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.
257
258
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.
259
260
260
261
**Create** a new cron job dynamically using the `SchedulerRegistry#addCronJob` method, as follows:
261
262
@@ -295,7 +296,7 @@ getCrons() {
295
296
jobs.forEach((value, key, map) => {
296
297
let next;
297
298
try {
298
-
next=value.nextDates().toDate();
299
+
next=value.nextDate().toJSDate();
299
300
} catch (e) {
300
301
next='error: next fire date is in the past!';
301
302
}
@@ -304,7 +305,7 @@ getCrons() {
304
305
}
305
306
```
306
307
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.
0 commit comments