Skip to content

Commit

Permalink
Merge pull request #227 from cumulus-nasa/CUMULUS-350
Browse files Browse the repository at this point in the history
CUMULUS-350 Update queue-granules to use cumulus-message-adapter
  • Loading branch information
Marc committed Mar 2, 2018
2 parents 8ad2fed + 0eb5d29 commit c5cfc5a
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 360 deletions.
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
* 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",
"@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

0 comments on commit c5cfc5a

Please sign in to comment.