Skip to content

Commit a2eff77

Browse files
authored
docs(techniques): fix wrong reference to SchedulerRegistry class
1 parent bf61568 commit a2eff77

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

content/techniques/task-scheduling.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ The `@nestjs/schedule` module provides a dynamic API that enables managing decla
225225
Obtain a reference to a `CronJob` instance by name from anywhere in your code using the `SchedulerRegistry` API. First, inject `SchedulerRegistry` using standard constructor injection:
226226

227227
```typescript
228-
constructor(private schedulerRegistry: SchedulerRegistry) {}
228+
constructor(private readonly schedulerRegistry: SchedulerRegistry) {}
229229
```
230230

231231
> info **Hint** Import the `SchedulerRegistry` from the `@nestjs/schedule` package.
@@ -258,7 +258,7 @@ The `getCronJob()` method returns the named cron job. The returned `CronJob` obj
258258

259259
> info **Hint** Use `toDate()` on `moment` objects to render them in human readable form.
260260
261-
**Create** a new cron job dynamically using the `SchedulerRegistry.addCronJob()` method, as follows:
261+
**Create** a new cron job dynamically using the `SchedulerRegistry#addCronJob` method, as follows:
262262

263263
```typescript
264264
addCronJob(name: string, seconds: string) {
@@ -275,11 +275,11 @@ addCronJob(name: string, seconds: string) {
275275
}
276276
```
277277

278-
In this code, we use the `CronJob` object from the `cron` package to create the cron job. The `CronJob` constructor takes a cron pattern (just like the `@Cron()` <a href="techniques/task-scheduling#declarative-cron-jobs">decorator</a>) as its first argument, and a callback to be executed when the cron timer fires as its second argument. The `SchedulerRegistry.addCronJob()` method takes two arguments: a name for the `CronJob`, and the `CronJob` object itself.
278+
In this code, we use the `CronJob` object from the `cron` package to create the cron job. The `CronJob` constructor takes a cron pattern (just like the `@Cron()` <a href="techniques/task-scheduling#declarative-cron-jobs">decorator</a>) as its first argument, and a callback to be executed when the cron timer fires as its second argument. The `SchedulerRegistry#addCronJob` method takes two arguments: a name for the `CronJob`, and the `CronJob` object itself.
279279

280280
> warning **Warning** Remember to inject the `SchedulerRegistry` before accessing it. Import `CronJob` from the `cron` package.
281281
282-
**Delete** a named cron job using the `SchedulerRegistry.deleteCronJob()` method, as follows:
282+
**Delete** a named cron job using the `SchedulerRegistry#deleteCronJob` method, as follows:
283283

284284
```typescript
285285
deleteCron(name: string) {
@@ -288,7 +288,7 @@ deleteCron(name: string) {
288288
}
289289
```
290290

291-
**List** all cron jobs using the `SchedulerRegistry.getCronJobs()` method as follows:
291+
**List** all cron jobs using the `SchedulerRegistry#getCronJobs` method as follows:
292292

293293
```typescript
294294
getCrons() {
@@ -309,7 +309,7 @@ The `getCronJobs()` method returns a `map`. In this code, we iterate over the ma
309309

310310
#### Dynamic intervals
311311

312-
Obtain a reference to an interval with the `SchedulerRegistry.getInterval()` method. As above, inject `SchedulerRegistry` using standard constructor injection:
312+
Obtain a reference to an interval with the `SchedulerRegistry#getInterval` method. As above, inject `SchedulerRegistry` using standard constructor injection:
313313

314314
```typescript
315315
constructor(private schedulerRegistry: SchedulerRegistry) {}
@@ -322,7 +322,7 @@ const interval = this.schedulerRegistry.getInterval('notifications');
322322
clearInterval(interval);
323323
```
324324

325-
**Create** a new interval dynamically using the `SchedulerRegistry.addInterval()` method, as follows:
325+
**Create** a new interval dynamically using the `SchedulerRegistry#addInterval` method, as follows:
326326

327327
```typescript
328328
addInterval(name: string, milliseconds: number) {
@@ -335,10 +335,10 @@ addInterval(name: string, milliseconds: number) {
335335
}
336336
```
337337

338-
In this code, we create a standard JavaScript interval, then pass it to the `ScheduleRegistry.addInterval()` method.
338+
In this code, we create a standard JavaScript interval, then pass it to the `SchedulerRegistry#addInterval` method.
339339
That method takes two arguments: a name for the interval, and the interval itself.
340340

341-
**Delete** a named interval using the `SchedulerRegistry.deleteInterval()` method, as follows:
341+
**Delete** a named interval using the `SchedulerRegistry#deleteInterval` method, as follows:
342342

343343
```typescript
344344
deleteInterval(name: string) {
@@ -347,7 +347,7 @@ deleteInterval(name: string) {
347347
}
348348
```
349349

350-
**List** all intervals using the `SchedulerRegistry.getIntervals()` method as follows:
350+
**List** all intervals using the `SchedulerRegistry#getIntervals` method as follows:
351351

352352
```typescript
353353
getIntervals() {
@@ -358,10 +358,10 @@ getIntervals() {
358358

359359
#### Dynamic timeouts
360360

361-
Obtain a reference to a timeout with the `SchedulerRegistry.getTimeout()` method. As above, inject `SchedulerRegistry` using standard constructor injection:
361+
Obtain a reference to a timeout with the `SchedulerRegistry#getTimeout` method. As above, inject `SchedulerRegistry` using standard constructor injection:
362362

363363
```typescript
364-
constructor(private schedulerRegistry: SchedulerRegistry) {}
364+
constructor(private readonly schedulerRegistry: SchedulerRegistry) {}
365365
```
366366

367367
And use it as follows:
@@ -371,7 +371,7 @@ const timeout = this.schedulerRegistry.getTimeout('notifications');
371371
clearTimeout(timeout);
372372
```
373373

374-
**Create** a new timeout dynamically using the `SchedulerRegistry.addTimeout()` method, as follows:
374+
**Create** a new timeout dynamically using the `SchedulerRegistry#addTimeout` method, as follows:
375375

376376
```typescript
377377
addTimeout(name: string, milliseconds: number) {
@@ -384,10 +384,10 @@ addTimeout(name: string, milliseconds: number) {
384384
}
385385
```
386386

387-
In this code, we create a standard JavaScript timeout, then pass it to the `ScheduleRegistry.addTimeout()` method.
387+
In this code, we create a standard JavaScript timeout, then pass it to the `SchedulerRegistry#addTimeout` method.
388388
That method takes two arguments: a name for the timeout, and the timeout itself.
389389

390-
**Delete** a named timeout using the `SchedulerRegistry.deleteTimeout()` method, as follows:
390+
**Delete** a named timeout using the `SchedulerRegistry#deleteTimeout` method, as follows:
391391

392392
```typescript
393393
deleteTimeout(name: string) {
@@ -396,7 +396,7 @@ deleteTimeout(name: string) {
396396
}
397397
```
398398

399-
**List** all timeouts using the `SchedulerRegistry.getTimeouts()` method as follows:
399+
**List** all timeouts using the `SchedulerRegistry#getTimeouts` method as follows:
400400

401401
```typescript
402402
getTimeouts() {

0 commit comments

Comments
 (0)