Skip to content

Commit

Permalink
Merge pull request #42 from nasa/CUMULUS-2203-update-to-Core3
Browse files Browse the repository at this point in the history
  • Loading branch information
Jkovarik authored Oct 20, 2020
2 parents def8217 + 9e24b68 commit e647463
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 27 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down Expand Up @@ -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"
}
Expand Down
16 changes: 9 additions & 7 deletions src/cma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import {
import {
CMAMessage,
CumulusMessageAdapterError,
CumulusMessageWithPayload,
CumulusMessageWithAssignedPayload,
InvokeCumulusMessageAdapterResult,
LoadNestedEventInput
} from './types';

import {
isCMAMessage,
isCumulusMessageWithPayload,
isCumulusMessageWithAssignedPayload,
isLoadNestedEventInput
} from './typeGuards';

Expand Down Expand Up @@ -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));
Expand All @@ -137,7 +137,7 @@ function setCumulusEnvironment(
async function getCmaOutput(
readLine: readline.ReadLine,
errorObj: CumulusMessageAdapterError
): Promise<CumulusMessageWithPayload | LoadNestedEventInput | CumulusRemoteMessage> {
): Promise<CumulusMessageWithAssignedPayload | LoadNestedEventInput | CumulusRemoteMessage> {
return new Promise((resolve, reject) => {
let buffer = '';
readLine.resume();
Expand Down Expand Up @@ -174,7 +174,7 @@ export async function runCumulusTask(
cumulusMessage: CumulusMessage | CumulusRemoteMessage | CMAMessage,
context: Context,
schemas: string | null = null
): Promise<CumulusMessage | CumulusRemoteMessage> {
): Promise<CumulusMessageWithAssignedPayload | CumulusRemoteMessage> {
const { cmaProcess, errorObj } = await invokeCumulusMessageAdapter();
const cmaStdin = cmaProcess.stdin;
const rl = readline.createInterface({
Expand All @@ -189,7 +189,7 @@ export async function runCumulusTask(
}));
cmaStdin.write('\n<EOC>\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)}`);
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export {
invokeCumulusMessageAdapter,
runCumulusTask
} from './cma';

export * from './types';
12 changes: 6 additions & 6 deletions src/message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CumulusMessageWithPayload } from './types';
import { CumulusMessageWithAssignedPayload } from './types';

const GRANULE_LOG_LIMIT = 500;
/**
Expand All @@ -12,7 +12,7 @@ const GRANULE_LOG_LIMIT = 500;
* @returns {Array<string>} - 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;
Expand All @@ -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;

/**
Expand All @@ -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;

/**
Expand All @@ -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;

/**
Expand All @@ -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;
12 changes: 6 additions & 6 deletions src/typeGuards.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
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
);
}

// 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
Expand Down
8 changes: 6 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit e647463

Please sign in to comment.