Skip to content

Commit e254385

Browse files
authored
Merge pull request #11209 from opencrvs/stream-batch-sizing-b
Stream batch sizing
2 parents 5d5b020 + 81d2e67 commit e254385

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/events/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const appModulePath = require('app-module-path')
2626
appModulePath.addPath(path.join(__dirname, '../'))
2727

2828
export async function main() {
29-
await ensureConnection()
3029
try {
30+
await ensureConnection()
3131
const anonymousToken = await getAnonymousToken()
3232
const configurations = await getInMemoryEventConfigurations(
3333
`Bearer ${anonymousToken}`

packages/events/src/service/events/reindex.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
1010
*/
1111
import { Readable, Transform, PassThrough } from 'node:stream'
12+
import { Agent } from 'node:http'
1213
import fetch from 'node-fetch'
1314
import { JsonStreamStringify } from 'json-stream-stringify'
1415
import { EventDocument } from '@opencrvs/commons/events'
@@ -98,7 +99,10 @@ export async function reindex(token: TokenWithBearer) {
9899
},
99100
// Converts object stream to JSON string stream so that it can
100101
// be sent to the country config reindex endpoint
101-
body: new JsonStreamStringify(eventDocumentStreamForCountryConfig)
102+
body: new JsonStreamStringify(eventDocumentStreamForCountryConfig),
103+
// Ensure HTTP socket of previous GET /events request is not reused
104+
// to avoid connections being closed preemptively by Node.js
105+
agent: new Agent({ keepAlive: false })
102106
}
103107
).then((response) => {
104108
if (!response.ok && response.status === 404) {

0 commit comments

Comments
 (0)