【发布时间】:2020-09-02 21:00:51
【问题描述】:
我正在构建一个通知触发方法,并希望在特定时间每天运行 3 次。
我已检查文档,但不了解该正则表达式代码以及如何根据需要对其进行自定义!
现在我的方法看起来像这样:(它现在在第 45 秒运行每分钟进行测试)我需要它例如在每天下午 6 点、晚上 8 点、晚上 11 点运行
@Cron('45 * * * * *')
async sendNotificaiotns() {
console.log('sending notification');
try {
const randomArticle = await this.articleRepository
.createQueryBuilder()
// .select("id")
// .getMany();
// .select("id")
.orderBy("RAND()")
.limit(1)
.getOne();
const input = new NotificationBySegmentBuilder()
.setIncludedSegments(['Active Users', 'Inactive Users'])
.notification() // .email()
.setAttachments({
data: {
...randomArticle,
},
big_picture: encodeURI(randomArticle.image)
})
.setHeadings({ 'en': randomArticle.title })
.setContents({'en': randomArticle.excerpt })
.build();
console.log(randomArticle);
await this.oneSignalService.createNotification(input);
} catch (e) {
console.log(e);
}
}
【问题讨论】:
标签: javascript node.js typescript nestjs cron-task