From 8f678b85f610e03a37e0325b17565d502980b71f Mon Sep 17 00:00:00 2001 From: Samika Kashyap Date: Wed, 22 May 2024 13:13:11 -0700 Subject: [PATCH] chore: add debug logs --- src/services/request-service.ts | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/services/request-service.ts b/src/services/request-service.ts index b13a7864..d484b928 100644 --- a/src/services/request-service.ts +++ b/src/services/request-service.ts @@ -50,12 +50,20 @@ export class RequestService { this.publishToQueue = Boolean(config.queue.sqsQueueUrl) } + /** + * Finds a request by CID from read replica first if not found there then from main db + * @param cid The CID of the request. + * @returns The request. + */ async getStatusForCid(cid: CID): Promise | { error: string }> { - const request = await this.requestRepository.findByCid(cid) + let request = await this.replicationRequestRepository.findByCid(cid) if (!request) { - throw new RequestDoesNotExistError(cid) + request = await this.requestRepository.findByCid(cid) + logger.debug(`Request not found in replica db for ${cid}, fetching from main_db`) + if (!request) { + throw new RequestDoesNotExistError(cid) + } } - logger.debug( `Found request for ${cid} of ${request.streamId} created at ${ISO8601_DATE_FORMAT.format( request.createdAt @@ -65,10 +73,20 @@ export class RequestService { return this.requestPresentationService.body(request) } + /** + * Finds a request by CID from read replica first if not found there then from main db + * @param cid The CID of the request. + * @returns The request. + */ async findByCid(cid: CID): Promise | undefined> { - // TODO: updated the call only here for now, upadte for calls - const found = await this.replicationRequestRepository.findByCid(cid) - if (!found) return undefined + let found = await this.replicationRequestRepository.findByCid(cid) + if (!found) { + found = await this.requestRepository.findByCid(cid) + logger.debug(`Request not found in replica db for ${cid}, fetching from main_db`) + if (!found) { + throw new RequestDoesNotExistError(cid) + } + } return this.requestPresentationService.body(found) }