I currently have a mat-table displaying Jobs and their details such as jobId, executionId, status, etc. In addition to this, I am using a WebSocket to receive notifications about the status of each job - whether it is Running, Successful, or Failed.
However, one issue I am facing with my WebSocket setup is that it does not distinguish between jobs based on Projects or Users. This means that even if User 2 runs a project, I will still receive notifications for Job Running.
To address this issue, I want to implement a condition in my code so that when I click on the stop button next to a job in my list, the code will compare the jobId and status to determine if the job was successfully stopped via the WebSocket response.
Here is the HTML code snippet for my Stop Job Button:
<button *ngIf="index === 0"
mat-icon-button
(click)="stop_exec_job(element)"
matTooltip="Stop Executing the Job"
[disabled]="element.status == 'Completed' || element.status == 'FINISH'"
>
<i class="material-icons" style="color:red"> stop </i>
</button>
The TypeScript function for stopping a job looks like this:
stop_exec_job(element) {
if (element.status == 'RUNNING' || element.status == 'Pending') {
//Api call to stop Job Execution
this.recommendationService
.stopJobExecution(element.jobId, element.status)
.subscribe(data => {
this.executeJobStop = data;
});
this.displaySpinner = false;
this.snakbar.statusBar('Job Execution Stopped', 'Success');
} else {
this.snakbar.statusBar('Job Failed to start', 'Failure');
}
}
Below is the snippet of code showing how messages from the WebSocket are handled:
this.messageService.messageReceived$.subscribe(data => {
let status: any = data;
this.snakbar.statusBar(
"Platform job status - " + status.message,
"Info"
);
});
I aim to only receive notifications from the WebSocket corresponding to the specific job that I have manually stopped by implementing appropriate if-else conditions. How can I achieve this?