Skip to content

Commit

Permalink
Apply sandbox init commands in small batches to avoid timeouts
Browse files Browse the repository at this point in the history
Co-authored-by: Leo Singer <[email protected]>
  • Loading branch information
ronitagarwala01 and lpsinger authored Nov 22, 2023
1 parent b3736a6 commit ca49c34
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import { pathToFileURL } from 'url'
import { Client } from '@opensearch-project/opensearch'
import type { ClientOptions } from '@opensearch-project/opensearch'
import { exists } from './paths'
import chunk from 'lodash/chunk'

const jsonFilename = 'sandbox-search.json'
const jsFilename = 'sandbox-search.js'

async function getData(path: string) {
async function getData(path: string): Promise<object[]> {
let result
const jsonPath = join(path, jsonFilename)
const jsPath = join(path, jsFilename)
Expand Down Expand Up @@ -44,6 +45,10 @@ export async function populate(path: string, opts: ClientOptions) {
const data = await getData(path)
if (data) {
const client = new Client(opts)
await client.bulk({ body: data })
const batch_size = 10
const batches = chunk(data, batch_size)
for (const batch of batches) {
await client.bulk({ body: batch })
}
}
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dependencies": {
"@opensearch-project/opensearch": "^2.2.0",
"env-paths": "^3.0.0",
"lodash": "^4.17.21",
"make-fetch-happen": "^11.0.3",
"rimraf": "^4.1.2",
"tar": "^6.1.13",
Expand All @@ -36,6 +37,7 @@
"devDependencies": {
"@nasa-gcn/eslint-config-gitignore": "^0.0.1",
"@tsconfig/node14": "^1.0.3",
"@types/lodash": "^4.14.202",
"@types/make-fetch-happen": "^10.0.1",
"@types/node": "^18.13.0",
"@types/tar": "^6.1.4",
Expand Down

0 comments on commit ca49c34

Please sign in to comment.