From 299942f356e490051a0af129abe771ce19862cc4 Mon Sep 17 00:00:00 2001 From: f-w Date: Wed, 13 Dec 2023 15:51:56 -0800 Subject: [PATCH] replaced fetch with axios due to timeout --- .github/values.ocp4.dev.yaml.gpg | Bin 1460 -> 1471 bytes package.json | 3 +- .../notifications/notifications.controller.ts | 18 ++++----- src/config.ts | 17 -------- test/notification.e2e-spec.ts | 37 ++++++------------ yarn.lock | 16 +++++++- 6 files changed, 37 insertions(+), 54 deletions(-) diff --git a/.github/values.ocp4.dev.yaml.gpg b/.github/values.ocp4.dev.yaml.gpg index a429c2cc2467fddc25103f250047433d5c68b15d..a94eddb3748482c1c0e5b1c4abc1ca9928429f8b 100644 GIT binary patch literal 1471 zcmV;w1wi_Y4Fm@R0+Iuu0j!ty0^-u@0Z>Uy*MQ!pKp1czzB#AoJ4o-6n)NBe$r)5T z`y8%P=e{-891yw83Kn6r#W{6Fc)*ed8-2Q0B&wfrfvT#zkIv${I21`po)q?vo&`RO zK8;s>-t%R|6p0V}l~uCq^19Z4A3xUhULUubkzU9*%8`zQ4K%SN2)$GmItK!DiBzgQ z1vB6e^Ag|IdgT{0#ip`B^VBG8n#9kIQF6({_SM{ZLXcYgZd|25%e7;2BOVn!#Q94Z7_Ta-HRKffwr=wA?g1!&*&gK9k0oQyq# z8rsQ8%d?QLQBOSe3T|^dxrHhWyX63o9Wyi+1z$NYo|jv}G6!g=KY3N>iLvh|WZCY7 z?K@J;zJ)F5&kj*$HV=p*WkWrL=m$9keX|2(3krF7-MDA12hQ2@TVwOh2T&XCbu{OB zZ8MQ0J;Me^hRLS=r%xv{Y{l~Q>qR3OSM2C=LD0ws-=QeS#XIR0%$|f1>6ac`^6Zw4 zme}6f3>3$^Q@!PSteM_Xgm(#JKR5eMVA$#=o&jAcY$|of-q&4ksU-A>mpH`5Jtf0w z&Zz)4Ncp$seuuW%<=gc`t_zcPi2XYD?@q-lPwHh}a~4H7Smn@<6#QB7kq>r_Pib!Q z+&W{JAg&3s$)r1=)0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.9", + "version": "5.0.10", "dbSchemaVersion": "0.9.0", "description": "A versatile notification API server", "author": "f-w", @@ -43,6 +43,7 @@ "@nestjs/platform-express": "^10.0.0", "@nestjs/swagger": "^7.1.8", "async": "^3.2.4", + "axios": "^1.6.2", "bcryptjs": "^2.4.3", "bottleneck": "^2.19.5", "class-transformer": "^0.5.1", diff --git a/src/api/notifications/notifications.controller.ts b/src/api/notifications/notifications.controller.ts index 706bf87b5..99816418f 100644 --- a/src/api/notifications/notifications.controller.ts +++ b/src/api/notifications/notifications.controller.ts @@ -21,6 +21,7 @@ import { HttpException, HttpStatus, Inject, + Logger, Param, ParseIntPipe, Patch, @@ -40,6 +41,7 @@ import { ApiTags, } from '@nestjs/swagger'; import { queue } from 'async'; +import axios from 'axios'; import { Request } from 'express'; import jmespath from 'jmespath'; import { pullAll } from 'lodash'; @@ -744,15 +746,8 @@ export class NotificationsController extends BaseController { data.id + '/broadcastToChunkSubscribers?start=' + task.startIdx; - const response = await fetch(uri); - if (response.status < 300) { - try { - return await response.json(); - } catch (ex) { - return response.body; - } - } - throw new HttpException(undefined, response.status); + const response = await axios.get(uri); + return response.data; }, broadcastSubRequestBatchSize); // re-submit task on error if // guaranteedBroadcastPushDispatchProcessing. @@ -760,6 +755,11 @@ export class NotificationsController extends BaseController { let failedChunks: any[] = []; q.error((_err: any, task: any) => { if (this.guaranteedBroadcastPushDispatchProcessing) { + Logger.debug(_err, NotificationsController.name); + Logger.debug( + `re-push task startIdx=${task.startIdx}`, + NotificationsController.name, + ); q.push(task); } else { data.state = 'error'; diff --git a/src/config.ts b/src/config.ts index b57cfc4b4..bf2f85e59 100644 --- a/src/config.ts +++ b/src/config.ts @@ -35,23 +35,6 @@ const config: Record = { host: '0.0.0.0', // port listen on port: 3000, - remoting: { - rest: { - normalizeHttpPath: false, - xml: false, - handleErrors: false, - }, - json: { - strict: false, - limit: '100kb', - }, - urlencoded: { - extended: true, - limit: '100kb', - }, - cors: false, - }, - legacyExplorer: false, adminIps: ['127.0.0.1'], siteMinderReverseProxyIps: ['127.0.0.1'], email: { diff --git a/test/notification.e2e-spec.ts b/test/notification.e2e-spec.ts index ae28b4fd5..d9d63b256 100644 --- a/test/notification.e2e-spec.ts +++ b/test/notification.e2e-spec.ts @@ -14,6 +14,7 @@ import { HttpException, HttpStatus } from '@nestjs/common'; import { NestExpressApplication } from '@nestjs/platform-express'; +import axios from 'axios'; import dns from 'dns'; import { merge } from 'lodash'; import nodemailer from 'nodemailer'; @@ -838,7 +839,7 @@ describe('POST /notifications', () => { broadcastSubRequestBatchSize: 10, }); appConfig.notification = newNotificationConfig; - const spiedFetch = jest.spyOn(global, 'fetch'); + const spiedAxios = jest.spyOn(axios, 'get'); const res = await client .post('/api/notifications') .send({ @@ -856,7 +857,7 @@ describe('POST /notifications', () => { expect( BaseController.prototype.sendEmail as unknown as jest.SpyInstance, ).toBeCalledTimes(2); - expect(spiedFetch).toBeCalledTimes(2); + expect(spiedAxios).toBeCalledTimes(2); const data = await notificationsService.findAll( { where: { @@ -882,28 +883,12 @@ describe('POST /notifications', () => { const spiedFetch = jest .spyOn(global, 'fetch') - .mockImplementation(async function (...args: any[]) { - if ( - args.length === 1 || - (args.length > 1 && args[1].method === undefined) - ) { - const getReq = client.get( - args[0].substring(args[0].indexOf('/api')), - ); - if (args[1]) { - for (const [p, v] of Object.entries(args[1].headers as object)) { - // eslint-disable-next-line @typescript-eslint/no-floating-promises - getReq.set(p, v); - } - } - const data: any = await getReq; - return new Response(JSON.stringify(data.body)); - } - if (args.length > 1 && args[1].method === 'POST') { - return new Response(); - } - throw new Error(); - }); + .mockResolvedValue(new Response()); + jest.spyOn(axios, 'get').mockImplementation(async (...args: any[]) => { + const getReq = client.get(args[0].substring(args[0].indexOf('/api'))); + const data: any = await getReq; + return new Response(JSON.stringify(data.body)); + }); ( BaseController.prototype.sendEmail as unknown as jest.SpyInstance @@ -1032,7 +1017,7 @@ describe('POST /notifications', () => { appConfig.notification = newNotificationConfig; const reqStub = jest - .spyOn(global, 'fetch') + .spyOn(axios, 'get') .mockRejectedValueOnce({ error: 'connection error' }); const res = await client .post('/api/notifications') @@ -1473,7 +1458,7 @@ describe('POST /notifications', () => { guaranteedBroadcastPushDispatchProcessing: false, }); appConfig.notification = newNotificationConfig; - jest.spyOn(global, 'fetch').mockRejectedValue({}); + jest.spyOn(axios, 'get').mockRejectedValue({}); const res = await client .post('/api/notifications') .send({ diff --git a/yarn.lock b/yarn.lock index e6fae6c45..5494a1c08 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2355,6 +2355,15 @@ axios@^0.26.1: dependencies: follow-redirects "^1.14.8" +axios@^1.6.2: + version "1.6.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.2.tgz#de67d42c755b571d3e698df1b6504cde9b0ee9f2" + integrity sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A== + dependencies: + follow-redirects "^1.15.0" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + babel-jest@^29.6.2: version "29.6.2" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-29.6.2.tgz#cada0a59e07f5acaeb11cbae7e3ba92aec9c1126" @@ -3610,7 +3619,7 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787" integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ== -follow-redirects@^1.14.8: +follow-redirects@^1.14.8, follow-redirects@^1.15.0: version "1.15.3" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.3.tgz#fe2f3ef2690afce7e82ed0b44db08165b207123a" integrity sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q== @@ -5704,6 +5713,11 @@ proxy-addr@~2.0.7: forwarded "0.2.0" ipaddr.js "1.9.1" +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + pump@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64"