Skip to content
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 5 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cumulus/tasks/discover-granules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const log = require('@cumulus/common/log');

/**
* Discover granules
* See schemas/input.json for detailed input schema
* 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
Expand Down
74 changes: 32 additions & 42 deletions cumulus/tasks/queue-granules/index.js
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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

* 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;
4 changes: 3 additions & 1 deletion cumulus/tasks/queue-granules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"license": "Apache-2.0",
"dependencies": {
"@cumulus/common": "^1.0.1",
"@cumulus/cumulus-message-adapter-js": "0.0.1-beta.3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this 1.0.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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",
Expand All @@ -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"
}
}
18 changes: 18 additions & 0 deletions cumulus/tasks/queue-granules/schemas/config.json
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" }
}
}
73 changes: 0 additions & 73 deletions cumulus/tasks/queue-granules/schemas/config.json.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
"title": "QueueGranulesInput",
"description": "Describes the input and config used by the queue-granules task",
"type": "object",
"require": [ "granules" ],
"properties": {
"pdr": {
"type": "object",
"required": ["name", "path"],
"properties": {
"name": { "type": "string" },
"path": { "type": "string" }
}
},
"granules": {
"type": "array",
"items": {
"type": "object",
"required": [ "files", "granuleId" ],
"properties": {
"name": { "type": "string" },
"granuleId": { "type": "string" },
"bucket": { "type": "string" },
"url_path": { "type": "string" }
"files": { "type": "array" }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"title": "QueueGranulesOutput",
"description": "Describes the output produced by the queue-granules task",
"type": "object",
"required": [ "granules_queued" ],
"properties": {
"granules_queued": {
"type": "integer"
}
"granules_queued": { "type": "integer" }
}
}
5 changes: 5 additions & 0 deletions cumulus/tasks/queue-granules/tests/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-param-reassign": "off"
}
}
Loading