-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #494 from stac-utils/jcw/post-ingest-notification
- Loading branch information
Showing
12 changed files
with
562 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { sns } from './aws-clients.js' | ||
import logger from './logger.js' | ||
import { isCollection, isItem } from './stac-utils.js' | ||
|
||
const attrsFromPayload = function (payload) { | ||
let type = 'unknown' | ||
let collection = '' | ||
if (isCollection(payload.record)) { | ||
type = 'Collection' | ||
collection = payload.record.id || '' | ||
} else if (isItem(payload.record)) { | ||
type = 'Item' | ||
collection = payload.record.collection || '' | ||
} | ||
|
||
return { | ||
recordType: { | ||
DataType: 'String', | ||
StringValue: type | ||
}, | ||
ingestStatus: { | ||
DataType: 'String', | ||
StringValue: payload.error ? 'failed' : 'successful' | ||
}, | ||
collection: { | ||
DataType: 'String', | ||
StringValue: collection | ||
} | ||
} | ||
} | ||
|
||
/* eslint-disable-next-line import/prefer-default-export */ | ||
export async function publishRecordToSns(topicArn, record, error) { | ||
const payload = { record, error } | ||
try { | ||
await sns().publish({ | ||
Message: JSON.stringify(payload), | ||
TopicArn: topicArn, | ||
MessageAttributes: attrsFromPayload(payload) | ||
}).promise() | ||
logger.info(`Wrote record ${record.id} to ${topicArn}`) | ||
} catch (err) { | ||
logger.error(`Failed to write record ${record.id} to ${topicArn}: ${err}`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function isCollection(record) { | ||
return record && record.type === 'Collection' | ||
} | ||
|
||
export function isItem(record) { | ||
return record && record.type === 'Feature' | ||
} |
Oops, something went wrong.