-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add table-streams trigger to index Circulars and send emails
This provides the backend for #612.
- Loading branch information
Showing
9 changed files
with
622 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*! | ||
* Copyright © 2022 United States Government as represented by the Administrator | ||
* of the National Aeronautics and Space Administration. No copyright is claimed | ||
* in the United States under Title 17, U.S. Code. All Other Rights Reserved. | ||
* | ||
* SPDX-License-Identifier: NASA-1.3 | ||
*/ | ||
|
||
// Type guarding to get around an error when trying to access `reason` | ||
const isRejected = ( | ||
input: PromiseSettledResult<unknown> | ||
): input is PromiseRejectedResult => input.status === 'rejected' | ||
|
||
/** | ||
* Create a Lambda trigger handler that handles event records concurrently, | ||
* asynchronously. | ||
*/ | ||
export function createTriggerHandler<T>( | ||
recordHandler: (record: T) => Promise<void> | ||
) { | ||
return async (event: { Records: T[] }) => { | ||
const results = await Promise.allSettled(event.Records.map(recordHandler)) | ||
const rejections = results.filter(isRejected).map(({ reason }) => reason) | ||
if (rejections.length) throw rejections | ||
} | ||
} |
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
Oops, something went wrong.