Adding auth and bootstrap message
This commit is contained in:
parent
62a4b8c9e6
commit
bd634f9742
2 changed files with 17 additions and 2 deletions
|
|
@ -14,10 +14,12 @@ export class NtfyClient {
|
|||
) {
|
||||
const host = this.configService.getOrThrow<string>('NTFY_HOST')
|
||||
this.topic = this.configService.getOrThrow<string>('NTFY_TOPIC')
|
||||
const token = this.configService.getOrThrow<string>('NTFY_TOKEN')
|
||||
this.httpClient = new Axios({
|
||||
baseURL: `https://${host}`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { InjectQueue, Process, Processor } from '@nestjs/bull'
|
||||
import { Inject, Injectable } from '@nestjs/common'
|
||||
import { Inject, Injectable, OnApplicationBootstrap } from '@nestjs/common'
|
||||
import { Job, JobOptions, Queue } from 'bull'
|
||||
import { Dayjs } from 'dayjs'
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ import {
|
|||
|
||||
@Processor(NTFY_PUBLISH_QUEUE_NAME)
|
||||
@Injectable()
|
||||
export class NtfyProvider {
|
||||
export class NtfyProvider implements OnApplicationBootstrap {
|
||||
constructor(
|
||||
@Inject(NtfyClient)
|
||||
private readonly ntfyClient: NtfyClient,
|
||||
|
|
@ -22,6 +22,10 @@ export class NtfyProvider {
|
|||
private readonly publishQueue: Queue,
|
||||
) {}
|
||||
|
||||
async onApplicationBootstrap() {
|
||||
await this.sendBootstrappedNotification()
|
||||
}
|
||||
|
||||
@Process()
|
||||
async handlePublishJob(job: Job<Omit<MessageConfig, 'topic'>>) {
|
||||
await this.ntfyClient.publish({
|
||||
|
|
@ -44,6 +48,15 @@ export class NtfyProvider {
|
|||
]
|
||||
}
|
||||
|
||||
async sendBootstrappedNotification() {
|
||||
await this.publishQueue.add(
|
||||
...NtfyProvider.defaultJob({
|
||||
title: 'Autobaan up and running',
|
||||
tags: [MessageTags.badminton],
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
async sendCronStartNotification(title: string) {
|
||||
await this.publishQueue.add(
|
||||
...NtfyProvider.defaultJob({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue