Files
wwjcloud-nest-v1/wwjcloud/test/test.service.ts

38 lines
985 B
TypeScript
Raw Normal View History

import { Injectable } from '@nestjs/common';
import { JobsService } from '../src/common/jobs/jobs.service';
import { EventBusService } from '../src/common/event-bus/event-bus.service';
@Injectable()
export class TestService {
constructor(
private readonly jobsService: JobsService,
private readonly eventBusService: EventBusService,
) {}
async publishKafkaEvent(
topic: string,
data: Record<string, any>,
): Promise<void> {
await this.eventBusService.publish(topic, {
event: 'test-event',
data,
occurredAt: new Date().toISOString(),
});
}
async enqueueRedisJob(
type: string,
payload: Record<string, any>,
): Promise<string> {
await this.jobsService.enqueue('test-queue', type, payload, {
attempts: 3,
backoffMs: 1000,
removeOnComplete: true,
removeOnFail: false,
});
// 生成一个模拟的 job ID
return `job_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
}
}