doctor-mail/apps/server/src/queue/worker/processor.ts

54 lines
1.7 KiB
TypeScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Job } from 'bullmq';
import { Logger } from '@nestjs/common';
import { ObjectType } from '@nice/common';
import { QueueJobType } from '../types';
import { updatePostViewCount } from '../models/post/utils';
const logger = new Logger('QueueWorker');
export default async function processJob(job: Job<any, any, QueueJobType>) {
try {
if (job.name === QueueJobType.UPDATE_STATS) {
const { sectionId, courseId, type } = job.data;
// 处理 section 统计
// if (sectionId) {
// await updateSectionLectureStats(sectionId);
// logger.debug(`Updated section stats for sectionId: ${sectionId}`);
// }
// // 如果没有 courseId提前返回
// if (!courseId) {
// return;
// }
// 处理 course 相关统计
switch (type) {
// case ObjectType.LECTURE:
// await updateCourseLectureStats(courseId);
// break;
// case ObjectType.ENROLLMENT:
// await updateCourseEnrollmentStats(courseId);
// break;
// case ObjectType.POST:
// await updateCourseReviewStats(courseId);
// break;
default:
logger.warn(`Unknown update stats type: ${type}`);
}
logger.debug(
`Updated course stats for courseId: ${courseId}, type: ${type}`,
);
}
if (job.name === QueueJobType.UPDATE_POST_VISIT_COUNT) {
await updatePostViewCount(job.data.id, job.data.type);
}
if (job.name === QueueJobType.UPDATE_POST_STATE) {
await updatePostViewCount(job.data.id, job.data.type);
}
} catch (error: any) {
logger.error(
`Error processing stats update job: ${error.message}`,
error.stack,
);
}
}