Skip to content

Commit 420ec43

Browse files
committed
fix: processed by moved one property up & fix analytics empty
1 parent f9ff550 commit 420ec43

File tree

6 files changed

+36
-81
lines changed

6 files changed

+36
-81
lines changed

api-generated/src/api.ts

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ export interface AnalyticsData {
3737
'id': string;
3838
/**
3939
*
40-
* @type {SendRequestJobData}
40+
* @type {SingleSendRequestDto}
4141
* @memberof AnalyticsData
4242
*/
43-
'data': SendRequestJobData;
43+
'data': SingleSendRequestDto;
4444
/**
4545
*
4646
* @type {string}
@@ -59,6 +59,12 @@ export interface AnalyticsData {
5959
* @memberof AnalyticsData
6060
*/
6161
'queue': string;
62+
/**
63+
*
64+
* @type {string}
65+
* @memberof AnalyticsData
66+
*/
67+
'processedBy': string;
6268
}
6369

6470
export const AnalyticsDataStatusEnum = {
@@ -139,55 +145,6 @@ export interface ResponseDto {
139145
*/
140146
'message': string;
141147
}
142-
/**
143-
*
144-
* @export
145-
* @interface SendRequestJobData
146-
*/
147-
export interface SendRequestJobData {
148-
/**
149-
*
150-
* @type {string}
151-
* @memberof SendRequestJobData
152-
*/
153-
'from': string;
154-
/**
155-
*
156-
* @type {string}
157-
* @memberof SendRequestJobData
158-
*/
159-
'to': string;
160-
/**
161-
*
162-
* @type {string}
163-
* @memberof SendRequestJobData
164-
*/
165-
'subject': string;
166-
/**
167-
*
168-
* @type {string}
169-
* @memberof SendRequestJobData
170-
*/
171-
'html': string;
172-
/**
173-
*
174-
* @type {string}
175-
* @memberof SendRequestJobData
176-
*/
177-
'replyTo': string;
178-
/**
179-
*
180-
* @type {string}
181-
* @memberof SendRequestJobData
182-
*/
183-
'directQueue': string;
184-
/**
185-
*
186-
* @type {string}
187-
* @memberof SendRequestJobData
188-
*/
189-
'processedBy': string;
190-
}
191148
/**
192149
*
193150
* @export
@@ -229,7 +186,7 @@ export interface SingleSendRequestDto {
229186
* @type {string}
230187
* @memberof SingleSendRequestDto
231188
*/
232-
'directQueue': string;
189+
'queue': string;
233190
}
234191
/**
235192
*
@@ -684,6 +641,9 @@ export const GatewayApiAxiosParamCreator = function (configuration?: Configurati
684641
const localVarHeaderParameter = {} as any;
685642
const localVarQueryParameter = {} as any;
686643

644+
// authentication Api-Key required
645+
await setApiKeyToObject(localVarHeaderParameter, "Authorization", configuration)
646+
687647

688648

689649
localVarHeaderParameter['Content-Type'] = 'application/json';

apps/consumer/src/app/consumer.service.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SendRequestJobData } from '@kir-mail/types';
1+
import { SingleSendRequestDto } from '@kir-mail/types';
22
import { Injectable, Logger, OnModuleDestroy } from '@nestjs/common';
33
import { MailerService } from '@nestjs-modules/mailer';
44
import { Job, MetricsTime, Worker } from 'bullmq';
@@ -21,7 +21,7 @@ export class ConsumerService implements OnModuleDestroy {
2121

2222
constructor(private readonly mailerService: MailerService) {
2323
for (const queueId of QUEUE_IDS) {
24-
this.logger.log(`Creating direct queue: ${queueId}`);
24+
this.logger.log(`Creating queue: ${queueId}`);
2525
this.workers.push(
2626
new Worker(queueId, this.process.bind(this), {
2727
connection: {
@@ -47,10 +47,9 @@ export class ConsumerService implements OnModuleDestroy {
4747
}
4848
}
4949

50-
async process(job: Job<SendRequestJobData>) {
50+
async process(job: Job<SingleSendRequestDto>) {
5151
this.logger.log(`Processing job #${job.id} 🔄`);
52-
await job.updateData({ ...job.data, processedBy: CONSUMER_NAME });
53-
52+
await new Promise((resolve) => setTimeout(resolve, 10000));
5453
try {
5554
if (!DISABLE_EMAILS)
5655
await this.mailerService.sendMail({
@@ -64,7 +63,6 @@ export class ConsumerService implements OnModuleDestroy {
6463
this.logger.error(`Job ${job.id} failed with error: ${error} 🚨`);
6564
throw error;
6665
}
67-
await job.updateData({ ...job.data, processedBy: CONSUMER_NAME });
6866
this.logger.log(`Job #${job.id} processed ✅`);
6967
}
7068
}

apps/dashboard/src/app/components/analytics-data-table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function AnalyticsDataTable({ data }: AnalyticsDataTableProps) {
2929
accessorKey: 'data.subject',
3030
header: 'Tárgy',
3131
},
32-
{ accessorKey: 'data.processedBy', header: 'Szolgáltatás' },
32+
{ accessorKey: 'processedBy', header: 'Szolgáltatás' },
3333
{ accessorKey: 'queue', header: 'Üzenetsor' },
3434
{ accessorKey: 'status', header: 'Státusz', cell: ({ row }) => <StatusBadge status={row.original.status} /> },
3535
]}

apps/gateway/src/app/gateway.service.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SendRequestJobData, SingleSendRequestDto } from '@kir-mail/types';
1+
import { SingleSendRequestDto } from '@kir-mail/types';
22
import { Injectable, InternalServerErrorException, Logger, NotFoundException } from '@nestjs/common';
33
import { Job, JobType, Queue } from 'bullmq';
44

@@ -10,7 +10,7 @@ const DEFAULT_QUEUE = 'send';
1010
@Injectable()
1111
export class GatewayService {
1212
private readonly logger = new Logger(GatewayService.name);
13-
private readonly directQueues: Queue[] = [];
13+
private readonly queues: Queue[] = [];
1414
constructor() {
1515
this.createQueue(DEFAULT_QUEUE);
1616
QUEUE_IDS.forEach((queueId) => this.createQueue(queueId));
@@ -31,7 +31,7 @@ export class GatewayService {
3131
},
3232
},
3333
});
34-
this.directQueues.push(queue);
34+
this.queues.push(queue);
3535
}
3636

3737
async sendMessage(request: SingleSendRequestDto) {
@@ -62,11 +62,11 @@ export class GatewayService {
6262
];
6363

6464
const jobs: AnalyticsData[] = [];
65-
6665
for (const type of types) {
67-
let rawJobs: Job<SendRequestJobData>[] = [];
68-
for (const queue of this.directQueues) {
69-
rawJobs = await queue.getJobs(type);
66+
const rawJobs: Job<SingleSendRequestDto>[] = [];
67+
for (const queue of this.queues) {
68+
const jobsForQueues = await queue.getJobs(type);
69+
rawJobs.push(...jobsForQueues);
7070
}
7171
jobs.push(...this.mapJobsToDto(rawJobs, type));
7272
}
@@ -82,28 +82,29 @@ export class GatewayService {
8282
return {
8383
items: splitJobs,
8484
timestamps: timestamps,
85-
availableQueues: this.directQueues.map((queue) => queue.name),
85+
availableQueues: this.queues.map((queue) => queue.name),
8686
};
8787
}
8888

8989
private getQueueForRequest(request: SingleSendRequestDto): Queue | undefined {
90-
if (request.directQueue) {
91-
return this.directQueues.find((queue) => queue.name === request.directQueue);
90+
if (request.queue) {
91+
return this.queues.find((queue) => queue.name === request.queue);
9292
}
9393
return this.getDefaultQueue();
9494
}
9595

9696
private getDefaultQueue(): Queue {
97-
return this.directQueues.find((queue) => queue.name === DEFAULT_QUEUE);
97+
return this.queues.find((queue) => queue.name === DEFAULT_QUEUE);
9898
}
9999

100-
private mapJobsToDto(jobs: Job<SendRequestJobData>[], status: JobType): AnalyticsData[] {
100+
private mapJobsToDto(jobs: Job<SingleSendRequestDto>[], status: JobType): AnalyticsData[] {
101101
return jobs.map((job) => ({
102102
id: job.id,
103103
data: job.data,
104104
status: status,
105105
timestamp: job.timestamp,
106106
queue: job.queueName,
107+
processedBy: job.processedBy,
107108
}));
108109
}
109110

apps/gateway/src/types/response.type.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SendRequestJobData } from '@kir-mail/types';
1+
import { SingleSendRequestDto } from '@kir-mail/types';
22
import { ApiProperty } from '@nestjs/swagger';
33
import { JobType } from 'bullmq';
44

@@ -14,8 +14,8 @@ export class AnalyticsData {
1414
@ApiProperty({ example: '1' })
1515
id: string;
1616

17-
@ApiProperty({ type: SendRequestJobData })
18-
data: SendRequestJobData;
17+
@ApiProperty({ type: SingleSendRequestDto })
18+
data: SingleSendRequestDto;
1919

2020
@ApiProperty({
2121
example: 'completed',
@@ -39,6 +39,9 @@ export class AnalyticsData {
3939

4040
@ApiProperty({ example: 'send' })
4141
queue: string;
42+
43+
@ApiProperty({ example: 'consumer' })
44+
processedBy: string;
4245
}
4346

4447
export class TimestampsDto {

types/src/lib/types.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ export class SingleSendRequestDto {
3131
queue?: string;
3232
}
3333

34-
export class SendRequestJobData extends SingleSendRequestDto {
35-
@ApiProperty({ example: 'consumer' })
36-
@IsString()
37-
@IsOptional()
38-
processedBy?: string;
39-
}
40-
4134
export class UserDto {
4235
@ApiProperty({ example: 'Test User' })
4336
@IsString()

0 commit comments

Comments
 (0)