ad monitoring

This commit is contained in:
Peter Maquiran
2024-08-21 11:37:47 +01:00
parent d76f2e240e
commit 82c67b8976
5 changed files with 51 additions and 19 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ export class ChatModule {
connection.subscribe((value) => {
if(value) {
// on connect
this.ChatServiceService.sendLocalMessages()
// this.ChatServiceService.sendLocalMessages()
}
})
@@ -45,7 +45,7 @@ export class MessageCreateUseCaseService {
) { }
@XTracerAsync({name:'MessageCreateUseCaseService', module:'chat', bugPrint: true})
@XTracerAsync({name:'MessageCreateUseCaseService', module:'chat', bugPrint: true, waitNThrow: 5000})
async execute(message: MessageEntity, messageEnum: RoomType, tracing?: TracingType) {
const validation = zodSafeValidation<MessageEntity>(MessageEntitySchema, message)
@@ -45,29 +45,29 @@ export class SendLocalMessagesUseCaseService {
console.log('to upload', messages)
const requestId = InstanceId +'@'+ uuidv4();
const DTO = MessageMapper.fromDomain(message, requestId)
await this.messageLocalDataSourceService.update(message.$id, { sending: true })
const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage<MessageOutPutDataDTO>(DTO)
if(sendMessageResult.isOk()) {
if(sendMessageResult.value.sender == undefined || sendMessageResult.value.sender == null) {
delete sendMessageResult.value.sender
}
let clone: MessageTable = {
...sendMessageResult.value,
id: sendMessageResult.value.id,
$id : message.$id
}
console.log('send message local '+ messages.length)
this.messageLocalDataSourceService.update(message.$id, {...clone, sending: false, roomId: message.roomId})
} else {
console.log('erro send message')
console.log('erro send message', sendMessageResult.error)
this.messageLocalDataSourceService.update(message.$id, {sending: false})
}
}
+23 -1
View File
@@ -1,5 +1,5 @@
import * as signalR from '@microsoft/signalr';
import { BehaviorSubject, Observable } from 'rxjs';
import { BehaviorSubject, Observable, race, timer } from 'rxjs';
import { ok, Result, err } from 'neverthrow';
import { SessionStore } from 'src/app/store/session.service';
import { filter, first } from 'rxjs/operators';
@@ -232,6 +232,28 @@ export class SignalRConnection {
resolve(ok(value));
});
// // Create an observable for the timeout (8 seconds)
// const timeout$ = timer(8000);
// // Create an observable for the message
// const message$ = this.messageUPdateSubject.pipe(
// filter((message: MessageOutPutDataDTO) => requestId === message?.requestId),
// first()
// );
// // Use race to choose whichever completes first (either the message or the timeout)
// race(message$, timeout$).subscribe({
// next: (value) => {
// if (typeof value === 'number') {
// // If the value is a number, it means the timeout fired
// reject(err('No response, timeout'));
// } else {
// resolve(ok(value));
// }
// },
// error: (error) => reject(err('Error: ' + error))
// });
} else {
this.sendLaterSubject.next({method: 'SendMessage', args: data})
return reject(err(false))
@@ -38,12 +38,10 @@ function convertAttributesToString(obj) {
}
const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingType => {
const createTracingInstance = ({bugPrint, name, module, autoFinish, waitNThrow}): TracingType => {
const startTime = Date.now();
const requestId = uuidv4()
let _tracerInstance:Tracer
if(module == 'notification') {
@@ -54,6 +52,8 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingTyp
_tracerInstance = tracerInstance
}
let waitNThrowFunction: NodeJS.Timeout
const span = _tracerInstance.startSpan(name);
let finish = false
@@ -134,6 +134,11 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingTyp
finish: () => {
if(finish) return
if(waitNThrowFunction) {
clearTimeout(waitNThrowFunction);
returnObject.hasError('waitNThrowFunction')
}
if(environment.apiURL != 'https://gdqas-api.oapr.gov.ao/api/') {
span.setAttribute('error.list', data.errors.join(','))
span.end();
@@ -158,10 +163,15 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingTyp
return tracerInstance.startSpan(name, { root: false }, parent) as Span;
}
}
if(waitNThrow) {
waitNThrowFunction = setTimeout(returnObject.finish, waitNThrow)
}
return returnObject
}
export function XTracerAsync({ name, bugPrint, module = null, autoFinish = true, daley =0 }) {
export function XTracerAsync({ name, bugPrint, module = null, autoFinish = true, daley =0, waitNThrow = 0 }) {
return (
target: unknown,
propertyKey: string,
@@ -172,7 +182,7 @@ export function XTracerAsync({ name, bugPrint, module = null, autoFinish = true,
const tracing = createTracingInstance({bugPrint, name, module, autoFinish})
const tracing = createTracingInstance({bugPrint, name, module, autoFinish, waitNThrow})
tracing.setAttribute('User', SessionStore?.user?.FullName);
tracing.setAttribute('current.page', window.location.pathname);
@@ -208,7 +218,7 @@ export function XTracerAsync({ name, bugPrint, module = null, autoFinish = true,
}
export function XTracer({ name, bugPrint, module, autoFinish = true, daley =0 }) {
export function XTracer({ name, bugPrint, module, autoFinish = true, daley =0, waitNThrow }) {
return (
target: unknown,
propertyKey: string,
@@ -217,7 +227,7 @@ export function XTracer({ name, bugPrint, module, autoFinish = true, daley =0 })
const originalMethod = descriptor.value;
descriptor.value = function (...args: unknown[]) {
const tracing = createTracingInstance({bugPrint, name, module, autoFinish})
const tracing = createTracingInstance({bugPrint, name, module, autoFinish, waitNThrow})
tracing.setAttribute('User', SessionStore?.user?.FullName);
tracing.setAttribute('current.page', window.location.pathname);