Merge pull request #3636 from omnivore-app/fix/send-push-notification

fix/send push notification
This commit is contained in:
Hongbo Wu
2024-03-06 12:18:42 +08:00
committed by GitHub
5 changed files with 27 additions and 5 deletions

View File

@ -59,7 +59,7 @@ const getImageSize = async (src: string): Promise<ImageSize | null> => {
height,
}
} catch (e) {
logger.error(e)
logger.error('get image size error', e)
return null
}
}

View File

@ -130,7 +130,7 @@ const triggerActions = async (
try {
await Promise.all(actionPromises)
} catch (error) {
logger.error(error)
logger.error('Error triggering rule actions', error)
}
}

View File

@ -13,6 +13,7 @@ import {
import express, { Express } from 'express'
import { appDataSource } from './data_source'
import { env } from './env'
import { aiSummarize, AI_SUMMARIZE_JOB_NAME } from './jobs/ai-summarize'
import { bulkAction, BULK_ACTION_JOB_NAME } from './jobs/bulk_action'
import { callWebhook, CALL_WEBHOOK_JOB_NAME } from './jobs/call_webhook'
import { findThumbnail, THUMBNAIL_JOB } from './jobs/find_thumbnail'
@ -43,7 +44,6 @@ import { redisDataSource } from './redis_data_source'
import { CACHED_READING_POSITION_PREFIX } from './services/cached_reading_position'
import { getJobPriority } from './utils/createTask'
import { logger } from './utils/logger'
import { AI_SUMMARIZE_JOB_NAME, aiSummarize } from './jobs/ai-summarize'
export const QUEUE_NAME = 'omnivore-backend-queue'
export const JOB_VERSION = 'v001'
@ -256,6 +256,16 @@ const main = async () => {
process.on('SIGINT', () => gracefulShutdown('SIGINT'))
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'))
process.on('uncaughtException', function (err) {
// Handle the error safely
logger.error('Uncaught exception', err)
})
process.on('unhandledRejection', (reason, promise) => {
// Handle the error safely
logger.error('Unhandled Rejection at: Promise', { promise, reason })
})
}
// only call main if the file was called from the CLI and wasn't required from another module

View File

@ -47,7 +47,7 @@ import {
isSystemRequest,
} from './utils/auth'
import { corsConfig } from './utils/corsConfig'
import { buildLogger, buildLoggerTransport } from './utils/logger'
import { buildLogger, buildLoggerTransport, logger } from './utils/logger'
import { aiSummariesRouter } from './routers/ai_summary_router'
const PORT = process.env.PORT || 4000
@ -247,6 +247,16 @@ const main = async (): Promise<void> => {
process.on('SIGINT', () => gracefulShutdown('SIGINT'))
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'))
process.on('uncaughtException', function (err) {
// Handle the error safely
logger.error('Uncaught exception', err)
})
process.on('unhandledRejection', (reason, promise) => {
// Handle the error safely
logger.error('Unhandled Rejection at: Promise', { promise, reason })
})
}
// only call main if the file was called from the CLI and wasn't required from another module

View File

@ -5,6 +5,7 @@ import { StatusType, User } from '../entity/user'
import { authTrx, getRepository, queryBuilderToRawSql } from '../repository'
import { userRepository } from '../repository/user'
import { SetClaimsRole } from '../utils/dictionary'
import { logger } from '../utils/logger'
import {
PushNotificationType,
sendMulticastPushNotifications,
@ -135,7 +136,8 @@ export const sendPushNotifications = async (
) => {
const tokens = await findDeviceTokensByUserId(userId)
if (tokens.length === 0) {
throw new Error('No device tokens found')
logger.info(`No device tokens found for user ${userId}`)
return
}
const message = {