forked from bloom-housing/bloom
-
Notifications
You must be signed in to change notification settings - Fork 1
Cron Task for 'Reminder to Update' Email Notifications
aisiri-murulidhar edited this page Dec 22, 2021
·
1 revision
For automatically sending reminder emails to property managers regarding updating their listings, we are using a cron job.
The cron module is defined at backend/core/src/cron/cron.module.ts
The cron service is defined at backend/core/src/cron/cron.service.ts
NestJS has support for Task Scheduling using the @nestjs/schedule package. For now we are setting the schedule to the first day of the month at noon. This can be changed to be more or less frequent in the future.
@Injectable()
export class CronService {
constructor(
private readonly emailService: EmailService,
private readonly listingsService: ListingsService,
private readonly userService: UserService
) {}
@Cron(CronExpression.EVERY_1ST_DAY_OF_MONTH_AT_NOON)
async handleCron() {
if (!process.env.SEND_NOTIFICATIONS_FOR_UPDATE_LISTINGS_REMINDER) {
return
}
Flag: When process.env.SEND_NOTIFICATIONS_FOR_UPDATE_LISTINGS_REMINDER is set to true, automated email reminders will begin.