-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathkafka-job-model-update-queue.ts
58 lines (51 loc) · 1.74 KB
/
kafka-job-model-update-queue.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Injectable, Logger } from '@nestjs/common';
import { Message, Producer } from 'kafkajs';
import { orchestratorConstants } from '../../auth/constants';
import {
CustomJobEntry,
CustomJobsDocument,
} from '../../database/custom-jobs/custom-jobs.model';
import { JobModelUpdateQueue } from './job-model-update-queue';
export interface KafkaJobModelUpdate extends CustomJobEntry {
image: string;
_id: string;
}
@Injectable()
export class KafkaJobModelUpdateQueue implements JobModelUpdateQueue {
private logger = new Logger(KafkaJobModelUpdateQueue.name);
constructor(private producer: Producer) {}
public async publish(...jobModelUpdates: CustomJobsDocument[]) {
for (const update of jobModelUpdates) {
const id = update._id.toString();
this.logger.debug(`Publishing job model update for jobId ${id}.`);
const modelUpdate: KafkaJobModelUpdate = {
_id: update._id,
name: update.name,
code: update.code,
container: update.container,
jobPodConfigId: update.jobPodConfigId,
language: update.language,
parameters: update.parameters,
type: update.type,
builtIn: update.builtIn,
category: update.category,
findingHandler: update.findingHandler,
findingHandlerEnabled: update.findingHandlerEnabled,
findingHandlerLanguage: update.findingHandlerLanguage,
image: update.container.image,
};
const serializedJobModelUpdate: Message[] = [
{
value: JSON.stringify({
id: id,
model: modelUpdate,
}),
},
];
await this.producer.send({
topic: orchestratorConstants.topics.jobModels,
messages: serializedJobModelUpdate,
});
}
}
}