-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CUMULUS-350 Update queue-granules to use cumulus-message-adapter #227
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,42 @@ | ||
'use strict'; | ||
|
||
const queueGranule = require('@cumulus/ingest/queue').queueGranule; | ||
const log = require('@cumulus/common/log'); | ||
const cumulusMessageAdapter = require('@cumulus/cumulus-message-adapter-js'); | ||
const { enqueueGranuleIngestMessage } = require('@cumulus/ingest/queue'); | ||
|
||
/** | ||
* Callback function provided by aws lambda. See https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html#nodejs-prog-model-handler-callback | ||
* @callback lambdaCallback | ||
* @param {object} error | ||
* @param {object} output - output object matching schemas/output.json | ||
* @param {integer} output.granules_queued | ||
*/ | ||
|
||
/** | ||
* For each Granule, generate a new SF messages send to the step function queue to be executed | ||
* @param {object} event lambda event object | ||
* @param {object} event.input | ||
* @param {array} event.input.granules | ||
* @param {object} context Lambda context object. See https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html | ||
* @param {lambdaCallback} callback callback function | ||
* @return {undefined} | ||
* See schemas/input.json and schemas/config.json for detailed event description | ||
* | ||
* @param {Object} event - Lambda event object | ||
* @returns {Promise} - see schemas/output.json for detailed output schema | ||
* that is passed to the next task in the workflow | ||
**/ | ||
function handler(event, context, cb) { | ||
const config = event.config; | ||
const stack = config.stack; | ||
const bucket = config.bucket; | ||
const queueUrl = config.queueUrl; | ||
const templateUri = config.templateUri; | ||
const provider = config.provider; | ||
const collection = config.collection; | ||
async function queueGranules(event) { | ||
const granules = event.input.granules || []; | ||
|
||
const queuedGranules = granules.map(g => queueGranule( | ||
g, | ||
queueUrl, | ||
templateUri, | ||
provider, | ||
collection, | ||
null, | ||
stack, | ||
bucket | ||
)); | ||
await Promise.all( | ||
granules.map((granule) => enqueueGranuleIngestMessage( | ||
granule, | ||
event.config.queueUrl, | ||
event.config.granuleIngestMessageTemplateUri, | ||
event.config.provider, | ||
event.config.collection, | ||
event.input.pdr | ||
)) | ||
); | ||
|
||
return Promise.all(queuedGranules).then(() => { | ||
cb(null, { granules_queued: queuedGranules.length }); | ||
}).catch((e) => { | ||
log.error(e); | ||
cb(e); | ||
}); | ||
return { granules_queued: granules.length }; | ||
} | ||
exports.queueGranules = queueGranules; | ||
|
||
module.exports.handler = handler; | ||
/** | ||
* Lambda handler | ||
* | ||
* @param {Object} event - a Cumulus Message | ||
* @param {Object} context - an AWS Lambda context | ||
* @param {Function} callback - an AWS Lambda handler | ||
* @returns {undefined} - does not return a value | ||
*/ | ||
function handler(event, context, callback) { | ||
cumulusMessageAdapter.runCumulusTask(queueGranules, event, context, callback); | ||
} | ||
exports.handler = handler; |
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 |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@cumulus/common": "^1.0.1", | ||
"@cumulus/cumulus-message-adapter-js": "0.0.1-beta.3", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should make this 1.0.0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created CUMULUS-367 to deal with this. |
||
"@cumulus/ingest": "^1.0.1", | ||
"babel-core": "^6.25.0", | ||
"babel-loader": "^6.2.4", | ||
|
@@ -51,6 +52,7 @@ | |
}, | ||
"devDependencies": { | ||
"@mapbox/mock-aws-sdk-js": "0.0.5", | ||
"ava": "^0.21.0" | ||
"ava": "^0.21.0", | ||
"lodash": "^4.17.5" | ||
} | ||
} |
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,18 @@ | ||
{ | ||
"title": "QueueGranulesConfig", | ||
"description": "Describes the config used by the queue-granules task", | ||
"type": "object", | ||
"required": [ | ||
"collection", | ||
"provider", | ||
"queueUrl", | ||
"granuleIngestMessageTemplateUri" | ||
], | ||
"additionalProperties": false, | ||
"properties": { | ||
"collection": { "type": "object" }, | ||
"provider": { "type": "object" }, | ||
"queueUrl": { "type": "string" }, | ||
"granuleIngestMessageTemplateUri": { "type": "string" } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
{ | ||
"rules": { | ||
"no-param-reassign": "off" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is returning an Object, not a Promise, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an async function, so it's returning a Promise.