diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dc368a..576fe36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [v2.0.0] 2020-10-19 + +### BREAKING CHANGES + +- **CUMULUS-2203** + - Updated CumulusMessageWithPayload exported to + CumulusMessageWithAssignedPayload. This change explicitly updates this type + to allow for a `null` payload value, as well as explicitly allows for a + `replace` key for compatibility with `@cumulus/types` > 3.0.0 + ## [v1.3.2] 2020-10-13 ### Fixed +- **CUMULUS_2203** + - Fixed issue causing spawned CMA process to left running/in the node event queue, resulting in AWS being unwilling/unable to clean up the instance. This resulted in lambdas with a memory leak/resource issues to not be reclaimed/restarted by AWS. diff --git a/package-lock.json b/package-lock.json index 971da20..2ce9fba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@cumulus/cumulus-message-adapter-js", - "version": "1.3.2", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -212,9 +212,9 @@ } }, "@cumulus/types": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@cumulus/types/-/types-2.0.1.tgz", - "integrity": "sha512-F5v6aBYMf1CdHevBP8l2+MxI0F1fNg/4L6MGgoMVvhuGIcW7iqI2QYNTJWl63Eglk8OhYXv5Oh6Yh0OwjEu2Ew==" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@cumulus/types/-/types-3.0.0.tgz", + "integrity": "sha512-qHqKIyLyWhDYBAPR01l1yCBrpWp07hE2RVnEThpZIQb3638I94LoD6DkQzluiRI59K7k4uP3GNqGfAtimL6PqQ==" }, "@nodelib/fs.scandir": { "version": "2.1.3", diff --git a/package.json b/package.json index c8e4dac..4439d4f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cumulus/cumulus-message-adapter-js", - "version": "1.3.2", + "version": "2.0.0", "description": "Cumulus message adapter", "main": "dist/index.js", "files": [ @@ -67,7 +67,7 @@ }, "dependencies": { "@types/aws-lambda": "^8.10.58", - "@cumulus/types": "2.0.1", + "@cumulus/types": "3.0.0", "execa": "^4.0.0", "lookpath": "1.0.3" } diff --git a/src/cma.ts b/src/cma.ts index ed45449..d692228 100644 --- a/src/cma.ts +++ b/src/cma.ts @@ -15,14 +15,14 @@ import { import { CMAMessage, CumulusMessageAdapterError, - CumulusMessageWithPayload, + CumulusMessageWithAssignedPayload, InvokeCumulusMessageAdapterResult, LoadNestedEventInput } from './types'; import { isCMAMessage, - isCumulusMessageWithPayload, + isCumulusMessageWithAssignedPayload, isLoadNestedEventInput } from './typeGuards'; @@ -114,7 +114,7 @@ function safeSetEnv(VARNAME: string, value?: string): void { * @returns {undefined} - no return values */ function setCumulusEnvironment( - cumulusMessage: CumulusMessageWithPayload, + cumulusMessage: CumulusMessageWithAssignedPayload, context: Context ): void { safeSetEnv('EXECUTIONS', getExecutions(cumulusMessage)); @@ -137,7 +137,7 @@ function setCumulusEnvironment( async function getCmaOutput( readLine: readline.ReadLine, errorObj: CumulusMessageAdapterError -): Promise { +): Promise { return new Promise((resolve, reject) => { let buffer = ''; readLine.resume(); @@ -174,7 +174,7 @@ export async function runCumulusTask( cumulusMessage: CumulusMessage | CumulusRemoteMessage | CMAMessage, context: Context, schemas: string | null = null -): Promise { +): Promise { const { cmaProcess, errorObj } = await invokeCumulusMessageAdapter(); const cmaStdin = cmaProcess.stdin; const rl = readline.createInterface({ @@ -189,7 +189,7 @@ export async function runCumulusTask( })); cmaStdin.write('\n\n'); const loadAndUpdateRemoteEventOutput = await getCmaOutput(rl, errorObj); - if (!isCumulusMessageWithPayload(loadAndUpdateRemoteEventOutput)) { + if (!isCumulusMessageWithAssignedPayload(loadAndUpdateRemoteEventOutput)) { throw new Error(`Invalid output typing recieved from loadAndUpdateRemoteEvent ${JSON.stringify(loadAndUpdateRemoteEventOutput)}`); } @@ -233,7 +233,9 @@ export async function runCumulusTask( console.log(`CMA process failed to kill on task failure: ${JSON.stringify(e)}`); } if (error?.name?.includes('WorkflowError') && (!isCMAMessage(cumulusMessage))) { - return { ...cumulusMessage, payload: null, exception: error.name }; + return { + ...cumulusMessage, payload: null, exception: error.name + } as CumulusMessageWithAssignedPayload; } throw error; } diff --git a/src/index.ts b/src/index.ts index 16ebd01..724a6cb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,3 +3,5 @@ export { invokeCumulusMessageAdapter, runCumulusTask } from './cma'; + +export * from './types'; diff --git a/src/message.ts b/src/message.ts index 7135f5d..b92fd4d 100644 --- a/src/message.ts +++ b/src/message.ts @@ -1,4 +1,4 @@ -import { CumulusMessageWithPayload } from './types'; +import { CumulusMessageWithAssignedPayload } from './types'; const GRANULE_LOG_LIMIT = 500; /** @@ -12,7 +12,7 @@ const GRANULE_LOG_LIMIT = 500; * @returns {Array} - An array of granule ids */ export const getMessageGranules = ( - message: CumulusMessageWithPayload, + message: CumulusMessageWithAssignedPayload, granuleLimit: number = GRANULE_LOG_LIMIT ): string[] => { const granules = message?.payload?.granules || message?.meta?.input_granules; @@ -30,7 +30,7 @@ export const getMessageGranules = ( * @returns {string | undefined} - The cumulus stack name. */ export const getStackName = ( - message: CumulusMessageWithPayload + message: CumulusMessageWithAssignedPayload ): string | undefined => message?.meta?.stack; /** @@ -40,7 +40,7 @@ export const getStackName = ( * @returns {string | undefined} - the parent execution. */ export const getParentArn = ( - message: CumulusMessageWithPayload + message: CumulusMessageWithAssignedPayload ): string | undefined => message?.cumulus_meta?.parentExecutionArn; /** @@ -50,7 +50,7 @@ export const getParentArn = ( * @returns {string | undefined} current execution name. */ export const getExecutions = ( - message: CumulusMessageWithPayload + message: CumulusMessageWithAssignedPayload ): string | undefined => message?.cumulus_meta?.execution_name; /** @@ -60,5 +60,5 @@ export const getExecutions = ( * @returns {string} asyncOperationId or null */ export const getAsyncOperationId = ( - message: CumulusMessageWithPayload + message: CumulusMessageWithAssignedPayload ): string | undefined => message?.cumulus_meta?.asyncOperationId; diff --git a/src/typeGuards.ts b/src/typeGuards.ts index 145eafb..1fa1d5b 100644 --- a/src/typeGuards.ts +++ b/src/typeGuards.ts @@ -1,20 +1,20 @@ import { CumulusMessage, CumulusRemoteMessage } from '@cumulus/types/message'; import { LoadNestedEventInput, - CumulusMessageWithPayload, + CumulusMessageWithAssignedPayload, CMAMessage } from './types'; // eslint-disable-next-line require-jsdoc -export function isCumulusMessageWithPayload( +export function isCumulusMessageWithAssignedPayload( message: CumulusMessage | CumulusRemoteMessage | - CumulusMessageWithPayload | + CumulusMessageWithAssignedPayload | LoadNestedEventInput -): message is CumulusMessageWithPayload { +): message is CumulusMessageWithAssignedPayload { return ( - (message as CumulusMessageWithPayload)?.payload !== undefined + (message as CumulusMessageWithAssignedPayload)?.payload !== undefined && (message as LoadNestedEventInput)?.input === undefined && (message as LoadNestedEventInput)?.config === undefined ); @@ -22,7 +22,7 @@ export function isCumulusMessageWithPayload( // eslint-disable-next-line require-jsdoc export function isLoadNestedEventInput( - message: CumulusMessageWithPayload | LoadNestedEventInput | CumulusRemoteMessage + message: CumulusMessageWithAssignedPayload | LoadNestedEventInput | CumulusRemoteMessage ): message is LoadNestedEventInput { return ( (message as LoadNestedEventInput).input !== undefined diff --git a/src/types.ts b/src/types.ts index dff3378..3616a63 100644 --- a/src/types.ts +++ b/src/types.ts @@ -13,14 +13,18 @@ export interface LoadNestedEventInput { config: unknown, messageConfig?: unknown } -export interface CumulusMessageWithPayload extends CumulusMessage { +export interface CumulusMessageWithAssignedPayload extends CumulusMessage { payload: { granules?: { granuleId: string }[] - } + [key: string]: unknown + } | null, meta: { + workflow_name: string + [key: string]: unknown stack?: string, input_granules?: { granuleId: string }[] } + replace?: ReplaceConfig } export interface CMAMessage { cma: {