EDSC-3612, make search results export asynchronous - #1588
Conversation
…sts__/handler.test.js
…-sqs, adding scripts for installing and running sqs and s3 simulations
…t S3 buckets, used by search exporting
…ss-configs/aws-resources.yml
…ocking of randomUUID
…onnections while running tests in parallel
…ng local development
|
|
||
| exportSearchRequest: | ||
| handler: serverless/src/exportSearchRequest/handler.default | ||
| timeout: 300 # this lambda isn't restricted to 30s because it's triggered by SQS not API Gateway |
There was a problem hiding this comment.
move comment down
| exportSearchRequest: | ||
| handler: serverless/src/exportSearchRequest/handler.default | ||
| timeout: 300 # this lambda isn't restricted to 30s because it's triggered by SQS not API Gateway | ||
| memorySize: 256 |
There was a problem hiding this comment.
keep memory default
| Properties: | ||
| QueueName: ${self:custom.siteName}-SearchExportQueue | ||
| ReceiveMessageWaitTimeSeconds: 20 | ||
| VisibilityTimeout: 300 |
There was a problem hiding this comment.
make larger than lambda timeout
| const authOptionalPaths = [ | ||
| '/autocomplete', | ||
| '/opensearch/granules', | ||
| '/collections/export' |
There was a problem hiding this comment.
put /collections/export back in
| const MOCK_KEY = '00000000-0000-0000-0000-000000000000' // see /__mocks__/crypto.js | ||
|
|
||
| // over-rides randomUUID to return the MOCK_KEY | ||
| jest.mock('crypto') |
There was a problem hiding this comment.
remove, for uuid package
| @@ -0,0 +1,124 @@ | |||
| import { randomUUID } from 'crypto' // if we do 'node:crypto', jest.mock won't work | |||
There was a problem hiding this comment.
use older library
| const earthdataEnvironment = determineEarthdataEnvironment(headers) | ||
|
|
||
| const jwt = getJwtToken(event) | ||
| if (!jwt) throw Error("missing jwt") |
There was a problem hiding this comment.
make jwt optional
|
|
||
| const { id: userId } = getVerifiedJwtToken(jwt, earthdataEnvironment) | ||
|
|
||
| if (!userId) throw Error("failed getting userId from jwt") |
There was a problem hiding this comment.
auth is optional now
| variables | ||
| } | ||
|
|
||
| const key = randomUUID() |
|
|
||
| const dbConnection = await getDbConnection() | ||
|
|
||
| await dbConnection('exports').insert({ |
| const searchExportQueueUrl = getSearchExportQueueUrl() | ||
| console.log('searchExportQueueUrl:', searchExportQueueUrl) | ||
|
|
||
| await sqs.sendMessage({ |
| QueueUrl: searchExportQueueUrl, | ||
| MessageBody: messageBody | ||
| }).promise() | ||
| console.log('posted to search export queue') |
There was a problem hiding this comment.
prefix with lambda name, proper caps
There was a problem hiding this comment.
and requestId!
| statusCode: 200, | ||
| headers: { | ||
| ...defaultResponseHeaders, | ||
| 'jwt-token': jwt |
| @@ -1,125 +1,189 @@ | |||
| import crypto from 'node:crypto' | |||
There was a problem hiding this comment.
uuid lib instead
| context.callbackWaitsForEmptyEventLoop = false | ||
|
|
||
| const { body, headers } = event | ||
| if (process.env.IS_OFFLINE || process.env.JEST_WORKER_ID) { |
| if (!filename) throw new Error("missing filename") | ||
| if (!key) throw new Error("missing key") | ||
| if (!requestId) throw new Error("missing requestId") | ||
| if (!userId) throw new Error("missing userId") |
| if (!userId) throw new Error("missing userId") | ||
|
|
||
| const { data, requestId } = JSON.parse(body) | ||
| const updateState = (state) => dbConnection('exports').where({ user_id: userId, key }).update({ state }) |
There was a problem hiding this comment.
userId optional
| "s3": "EXTRA_CORS_ALLOWED_ORIGINS=http://localhost:5000 MOTO_ALLOW_NONEXISTENT_REGION=True moto_server -H 0.0.0.0", | ||
| "s3:install": "brew install moto", | ||
| "s3:reset": "curl -X POST http://localhost:5000/moto-api/reset", | ||
| "sqs": "java -jar elasticmq-server-1.3.9.jar", |
There was a problem hiding this comment.
I'd rather have sqs offline set up the same way as other projects our team manages, with the docker compose file.
I hate the idea of running extra processes in order to run EDSC locally. This PR for serverless offline sqs shows that it is possible to disable sqs offline. So we'd get the benefit of queues locally, but only if the dev wants them. I don't think that is happening, but it is easy enough to open a new PR that is up to date and install the forked version of the plugin
|
superseded by #1630 |
Overview
What is the feature?
Please summarize the feature or fix.
What is the Solution?
Summarize what you changed.
What areas of the application does this impact?
List impacted areas.
Testing
Reproduction steps
Attachments
Please include relevant screenshots or files that would be helpful in reviewing and verifying this change.
Checklist