Skip to content

Commit

Permalink
Merge pull request #52 from Opetushallitus/fix/opensearch-delay-after…
Browse files Browse the repository at this point in the history
…-index-creation

Delay code for 2 seconds after index deletion
  • Loading branch information
MikkoKauhanen authored Jan 3, 2025
2 parents 8786217 + 97730b0 commit afc31cc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
3 changes: 1 addition & 2 deletions aoe-infra/environments/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,13 @@
"memory_limit": "1024",
"min_count": 1,
"max_count": 1,
"image_tag": "ga-230",
"image_tag": "ga-242",
"allow_ecs_exec": true,
"env_vars": {
"PID_SERVICE_URL": "http://localhost",
"NODE_ENV": "production",
"LOG_LEVEL": "error",
"PORT_LISTEN": "8080",
"TEST_RUN": "false",
"MATERIAL_VERSION_URL": "https://dev.aoe.fi/#/materiaali/",
"HTTP_OPTIONS_TIMEOUT": "5000",
"HTTP_OPTIONS_RETRY": "2",
Expand Down
2 changes: 0 additions & 2 deletions aoe-web-backend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ PORT=3000

NODE_TLS_REJECT_UNAUTHORIZED=0

TEST_RUN=true

## AOE server and service component general purpose configurations
SERVER_CONFIG_OAIPMH_ANALYTICS_URL=http://aoe-data-analytics:8080

Expand Down
12 changes: 2 additions & 10 deletions aoe-web-backend/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const missingEnvs: string[] = [];
process.env.NODE_ENV || missingEnvs.push('NODE_ENV');
process.env.PORT_LISTEN || missingEnvs.push('PORT_LISTEN');
process.env.LOG_LEVEL || missingEnvs.push('LOG_LEVEL');
process.env.TEST_RUN || missingEnvs.push('TEST_RUN');
process.env.CLOUD_STORAGE_ENABLED || missingEnvs.push('CLOUD_STORAGE_ENABLED');
process.env.CLOUD_STORAGE_REGION || missingEnvs.push('CLOUD_STORAGE_REGION');
process.env.CLOUD_STORAGE_BUCKET || missingEnvs.push('CLOUD_STORAGE_BUCKET');
Expand Down Expand Up @@ -48,14 +47,8 @@ process.env.STREAM_STATUS_PATH || missingEnvs.push('STREAM_STATUS_PATH');
process.env.STREAM_STATUS_HOST_HTTPS_ENABLED || missingEnvs.push('STREAM_STATUS_HOST_HTTPS_ENABLED');
process.env.PID_API_KEY || missingEnvs.push('PID_API_KEY');
process.env.PID_SERVICE_URL || missingEnvs.push('PID_SERVICE_URL');

if (process.env.TEST_RUN === 'true') {
process.env.PG_USER || missingEnvs.push('POSTGRES_USER');
process.env.PG_PASS || missingEnvs.push('POSTGRES_PASSWORD');
} else {
process.env.PG_USER || missingEnvs.push('POSTGRES_USER_SECONDARY');
process.env.PG_PASS || missingEnvs.push('POSTGRES_PASSWORD_SECONDARY');
}
process.env.PG_USER || missingEnvs.push('PG_USER');
process.env.PG_PASS || missingEnvs.push('PG_PASS');

if (missingEnvs.length > 0) {
winstonLogger.error('All required environment variables are not available: %s', missingEnvs);
Expand All @@ -69,7 +62,6 @@ export default {
logLevel: process.env.LOG_LEVEL as string,
nodeEnv: process.env.NODE_ENV as string,
portListen: parseInt(process.env.PORT_LISTEN as string, 10) as number,
testRun: ((process.env.TEST_RUN as string).toLowerCase() === 'true') as boolean,
} as const,

// Cloud storage configurations.
Expand Down
3 changes: 3 additions & 0 deletions aoe-web-backend/src/search/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ export const deleteIndex = async (index: string): Promise<boolean> => {
return false;
}

// delay added due to opensearch serverless issue with old index still being used for bulk
await new Promise((resolve) => setTimeout(resolve, 2000));

for (let attempt = 0; attempt < 5; attempt++) {
const exists = await indexExists(index);
if (!exists) {
Expand Down

0 comments on commit afc31cc

Please sign in to comment.