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')
|
const host = this.configService.getOrThrow<string>('NTFY_HOST')
|
||||||
this.topic = this.configService.getOrThrow<string>('NTFY_TOPIC')
|
this.topic = this.configService.getOrThrow<string>('NTFY_TOPIC')
|
||||||
|
const token = this.configService.getOrThrow<string>('NTFY_TOKEN')
|
||||||
this.httpClient = new Axios({
|
this.httpClient = new Axios({
|
||||||
baseURL: `https://${host}`,
|
baseURL: `https://${host}`,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { InjectQueue, Process, Processor } from '@nestjs/bull'
|
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 { Job, JobOptions, Queue } from 'bull'
|
||||||
import { Dayjs } from 'dayjs'
|
import { Dayjs } from 'dayjs'
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@ import {
|
||||||
|
|
||||||
@Processor(NTFY_PUBLISH_QUEUE_NAME)
|
@Processor(NTFY_PUBLISH_QUEUE_NAME)
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class NtfyProvider {
|
export class NtfyProvider implements OnApplicationBootstrap {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(NtfyClient)
|
@Inject(NtfyClient)
|
||||||
private readonly ntfyClient: NtfyClient,
|
private readonly ntfyClient: NtfyClient,
|
||||||
|
|
@ -22,6 +22,10 @@ export class NtfyProvider {
|
||||||
private readonly publishQueue: Queue,
|
private readonly publishQueue: Queue,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
async onApplicationBootstrap() {
|
||||||
|
await this.sendBootstrappedNotification()
|
||||||
|
}
|
||||||
|
|
||||||
@Process()
|
@Process()
|
||||||
async handlePublishJob(job: Job<Omit<MessageConfig, 'topic'>>) {
|
async handlePublishJob(job: Job<Omit<MessageConfig, 'topic'>>) {
|
||||||
await this.ntfyClient.publish({
|
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) {
|
async sendCronStartNotification(title: string) {
|
||||||
await this.publishQueue.add(
|
await this.publishQueue.add(
|
||||||
...NtfyProvider.defaultJob({
|
...NtfyProvider.defaultJob({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue