Skip to content

Commit ad3a258

Browse files
author
Phil Varner
authored
ingest failures will propagate to a lambda failure (#664)
* ingest error will return an error from the lambda * changelog
1 parent 4b84017 commit ad3a258

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Changed
1111

12+
- Ingest lambda will return a failure if there are errors during ingesting. Previously,
13+
errors would only be logged and the lambda would always return a success response.
1214
- Landing page (/) and collections endpoint (/collections) now return a 500 if
1315
create_indices has not been run or cannot connect to database.
1416

src/lambdas/ingest/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,16 @@ export const handler = async (event, _context) => {
6161
: [event]
6262

6363
try {
64+
logger.debug('Attempting to ingest %d items', stacItems.length)
65+
6466
const results = await ingestItems(stacItems)
65-
logger.debug('Ingested %d items: %j', stacItems.length, stacItems)
67+
68+
const errorCount = results.filter((result) => result.error).length
69+
if (errorCount) {
70+
logger.debug('There were %d errors ingesting %d items', errorCount, stacItems.length)
71+
} else {
72+
logger.debug('Ingested %d items', results.length)
73+
}
6674

6775
const postIngestTopicArn = process.env['POST_INGEST_TOPIC_ARN']
6876

@@ -72,6 +80,8 @@ export const handler = async (event, _context) => {
7280
} else {
7381
logger.debug('Skipping post-ingest notification since no topic is configured')
7482
}
83+
84+
if (errorCount) throw new Error('There was at least one error ingesting items.')
7585
} catch (error) {
7686
logger.error(error)
7787
throw (error)

src/lib/ingest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function logIngestItemsResults(results) {
132132
if (result.error instanceof InvalidIngestError) {
133133
// Attempting to ingest invalid stac objects is not a system error so we
134134
// log it as info and not error
135-
logger.info('Invalid ingest item', result.error)
135+
logger.warn('Invalid ingest item', result.error)
136136
} else {
137137
logger.error('Error while ingesting item', result.error)
138138
}

tests/helpers/ingest.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const ingestFixtureC = (ingestTopicArn, ingestQueueUrl) =>
7474
overrides
7575
})
7676

77-
export async function testPostIngestSNS(t, record) {
77+
export async function testPostIngestSNS(t, record, shouldError = false) {
7878
// @ts-ignore
7979
process.env.POST_INGEST_TOPIC_ARN = t.context.postIngestTopicArn
8080

@@ -83,7 +83,13 @@ export async function testPostIngestSNS(t, record) {
8383
Message: JSON.stringify(record)
8484
})
8585

86-
await sqsTriggerLambda(t.context.ingestQueueUrl, handler)
86+
try {
87+
await sqsTriggerLambda(t.context.ingestQueueUrl, handler)
88+
} catch (e) {
89+
if (!shouldError) {
90+
t.fail('Ingest had error, but should not have.')
91+
}
92+
}
8793

8894
const { Messages } = await sqs().receiveMessage({
8995
QueueUrl: t.context.postIngestQueueUrl,

tests/system/test-ingest.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ test('Ingest collection failure is published to post-ingest SNS topic', async (t
392392
const { message, attrs } = await testPostIngestSNS(t, {
393393
type: 'Collection',
394394
id: 'badCollection'
395-
})
395+
}, true)
396396

397397
t.is(message.record.id, 'badCollection')
398398
t.is(attrs.collection.Value, 'badCollection')
@@ -482,7 +482,7 @@ test('Ingest item failure is published to post-ingest SNS topic', async (t) => {
482482
type: 'Feature',
483483
id: 'badItem',
484484
collection: collection.id
485-
})
485+
}, true)
486486

487487
t.is(message.record.id, 'badItem')
488488
t.is(attrs.collection.Value, collection.id)
@@ -514,7 +514,7 @@ test('Ingested item is published to post-ingest SNS topic with updated links', a
514514
}
515515
})
516516

517-
test('Ingested item facilure is published to post-ingest SNS topic without updated links', async (t) => {
517+
test('Ingested item failure is published to post-ingest SNS topic without updated links', async (t) => {
518518
const envBeforeTest = { ...process.env }
519519
try {
520520
const hostname = 'some-stac-server.com'
@@ -526,7 +526,7 @@ test('Ingested item facilure is published to post-ingest SNS topic without updat
526526
{ id: randomId('item'), collection: 'INVALID COLLECTION' }
527527
)
528528

529-
const { message } = await testPostIngestSNS(t, item)
529+
const { message } = await testPostIngestSNS(t, item, true)
530530

531531
t.truthy(message.record.links)
532532
t.false(message.record.links.every((/** @type {Link} */ link) => (

0 commit comments

Comments
 (0)