Skip to content
Snippets Groups Projects
Commit 8891e85d authored by Marcos Pieras's avatar Marcos Pieras
Browse files

feat: adds updates

parent 044faf06
No related branches found
No related tags found
5 merge requests!42test: adds return message to handle e2e tests,!40test: adds test on populate template,!37chore: adds precommit and commitlint,!35test: adds tests on statcheck and diffcheck,!34test: adds tests for query service
Pipeline #146814 passed
No preview for this file type
......@@ -87,6 +87,8 @@ export const queryServiceReader = async (frontendPublisher: RabbitMqBroker, mlPu
}
log.info('Starting query reader for', type);
const publisher = new QueryPublisher(frontendPublisher, mlPublisher);
const queryServiceConsumer = await new RabbitMqBroker(
rabbitMq,
'requests-exchange',
......
......@@ -6,19 +6,35 @@ import type { RabbitMqBroker } from 'ts-common/rabbitMq';
export class QueryPublisher {
private frontendPublisher: RabbitMqBroker;
private mlPublisher: RabbitMqBroker;
private routingKey: string;
private headers: BackendMessageHeader;
private queryID: number;
private routingKey?: string;
private headers?: BackendMessageHeader;
private queryID?: string;
constructor(frontendPublisher: RabbitMqBroker, mlPublisher: RabbitMqBroker, headers: BackendMessageHeader, queryID: number) {
constructor(frontendPublisher: RabbitMqBroker, mlPublisher: RabbitMqBroker) {
this.frontendPublisher = frontendPublisher;
this.mlPublisher = mlPublisher;
}
withHeaders(headers?: BackendMessageHeader) {
this.headers = headers;
this.routingKey = headers.routingKey;
return this;
}
withRoutingKey(routingKey?: string) {
this.routingKey = routingKey;
return this;
}
withQueryID(queryID?: string) {
this.queryID = queryID;
return this;
}
publishStatusToFrontend(status: string) {
if (!this.headers || !this.routingKey || !this.queryID) {
throw new Error('Headers or RoutingKey or queryID not set');
}
this.frontendPublisher.publishMessageToFrontend(
{
type: wsReturnKey.queryStatusUpdate,
......@@ -32,6 +48,10 @@ export class QueryPublisher {
}
publishErrorToFrontend(reason: string) {
if (!this.headers || !this.routingKey || !this.queryID) {
throw new Error('Headers or RoutingKey or queryID not set');
}
this.frontendPublisher.publishMessageToFrontend(
{
type: wsReturnKey.queryStatusError,
......@@ -45,13 +65,17 @@ export class QueryPublisher {
}
publishTranslationResultToFrontend(query: string) {
if (!this.headers || !this.routingKey || !this.queryID) {
throw new Error('Headers or RoutingKey or queryID not set');
}
this.frontendPublisher.publishMessageToFrontend(
{
type: wsReturnKey.queryStatusTranslationResult,
callID: this.headers.callID,
value: {
result: query,
queryID: this.queryID,
queryID: this.headers.callID,
},
status: 'success',
},
......@@ -61,6 +85,10 @@ export class QueryPublisher {
}
publishResultToFrontend(result: GraphQueryResultMetaFromBackend) {
if (!this.headers || !this.routingKey || !this.queryID) {
throw new Error('Headers or RoutingKey or queryID not set');
}
this.frontendPublisher.publishMessageToFrontend(
{
type: wsReturnKey.queryStatusResult,
......@@ -70,7 +98,7 @@ export class QueryPublisher {
type: 'nodelink',
payload: result,
},
queryID: this.queryID,
queryID: this.headers.callID,
},
status: 'success',
},
......@@ -80,6 +108,10 @@ export class QueryPublisher {
}
publishMachineLearningRequest(result: GraphQueryResultFromBackend, mlAttributes: MachineLearning, headers: BackendMessageHeader) {
if (!this.headers || !this.routingKey) {
throw new Error('Headers or RoutingKey or queryID not set');
}
// FIXME: Change ML to use the same message format that the frontend uses
const toMlResult = {
nodes: result.nodes.map(node => ({ ...node, id: node._id })),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment