Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

Commit 8a0f06e

Browse files
committed
docs: add new notification service in README.md
1 parent a0959d2 commit 8a0f06e

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

README.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- [app.module.ts](#appmodulets)
3131
- [notification.module.ts](#notificationmodulets)
3232
- [notification.processor.ts](#notificationprocessorts)
33+
- [notification.service.ts](#notificationservicets)
3334
- [Contributing](#contributing)
3435
- [License](#license)
3536
</details>
@@ -113,23 +114,28 @@ export class NotificationsModule {}
113114
// src/notification/notification.processor.ts
114115

115116
import { Job } from '@pulsecron/nestjs-pulse';
116-
import { Every, Queue } from '@pulsecron/nestjs-pulse';
117+
import { Every, Queue, Define, Schedule } from '@pulsecron/nestjs-pulse';
117118

118119
@Queue('notifications')
119120
export class NotificationsQueue {
120-
@Every({ name: 'send notifications', interval: '2 minutes' })
121+
@Every({ name: 'send notifications', interval: '1 minutes' })
121122
async sendNotifications(job: Job) {
122-
console.log('Sending notifications');
123+
console.log('Sending notifications[1]');
123124
}
124125

125-
@Scheduler({ name: 'send notifications', when: 'tomorrow at noon' })
126+
@Schedule({ name: 'send notifications', when: 'tomorrow at noon' })
126127
async sendNotifications(job: Job) {
127-
console.log('Sending notifications');
128+
console.log('Sending notifications[2]');
128129
}
129130

130131
@Now()
131132
async sendNotifications(job: Job) {
132-
console.log('Sending notifications');
133+
console.log('Sending notifications[3]');
134+
}
135+
136+
@Define({ name: 'emailJob' })
137+
async test(job: Job) {
138+
console.log('Sending email to:', job.data.to);
133139
}
134140
}
135141

@@ -138,6 +144,33 @@ export class NotificationsQueue {
138144
```
139145

140146

147+
##### notification.service.ts
148+
```typescript
149+
150+
import { Injectable } from '@nestjs/common';
151+
import { Inject } from '@nestjs/common';
152+
153+
@Injectable()
154+
export class NotificationService {
155+
constructor(@Inject('notifications') private pulse: Pulse) {}
156+
157+
async scheduleEmail(email: string) {
158+
const emailJob = this.pulse.create('emailJob', { to: email });
159+
emailJob.unique(
160+
{
161+
'data.to': email,
162+
},
163+
{
164+
insertOnly: true,
165+
}
166+
);
167+
emailJob.schedule('5 seconds').save();
168+
}
169+
}
170+
171+
172+
```
173+
141174
---
142175
<br/>
143176
<br/>

0 commit comments

Comments
 (0)