Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
generateDocFromPayload(payload) {
const name = get(payload, 'cumulus_meta.execution_name');
const arn = aws.getExecutionArn(
get(payload, 'cumulus_meta.state_machine'),
name
);
if (!arn) {
throw new Error('State Machine Arn is missing. Must be included in the cumulus_meta');
}
const execution = aws.getExecutionUrl(arn);
const collectionId = constructCollectionId(
get(payload, 'meta.collection.name'), get(payload, 'meta.collection.version')
);
const doc = {
name,
arn,
parentArn: get(payload, 'cumulus_meta.parentExecutionArn'),
execution,
tasks: get(payload, 'meta.workflow_tasks'),
error: parseException(payload.exception),
type: get(payload, 'meta.workflow_name'),
collectionId: collectionId,
status: get(payload, 'meta.status', 'unknown'),
createdAt: get(payload, 'cumulus_meta.workflow_start_time'),
timestamp: Date.now()
const getGranuleRecordsFromCumulusMessage = async (cumulusMessage) => {
const granules = getMessageGranules(cumulusMessage);
if (!granules) {
log.info(`No granules to process in the payload: ${JSON.stringify(cumulusMessage.payload)}`);
return [];
}
const executionArn = getMessageExecutionArn(cumulusMessage);
const executionUrl = getExecutionUrl(executionArn);
let executionDescription;
try {
executionDescription = await StepFunctions.describeExecution({ executionArn });
} catch (err) {
log.error(`Could not describe execution ${executionArn}`, err);
}
const promisedGranuleRecords = granules
.map(async (granule) => {
try {
return await Granule.generateGranuleRecord(
granule,
cumulusMessage,
executionUrl,
executionDescription
createGranulesFromSns(payload) {
const name = get(payload, 'cumulus_meta.execution_name');
const granules = get(payload, 'payload.granules', get(payload, 'meta.input_granules'));
if (!granules) return Promise.resolve();
const arn = aws.getExecutionArn(
get(payload, 'cumulus_meta.state_machine'),
name
);
if (!arn) return Promise.resolve();
const execution = aws.getExecutionUrl(arn);
const collection = get(payload, 'meta.collection');
const exception = parseException(payload.exception);
const collectionId = constructCollectionId(collection.dataType, collection.version);
const done = granules.map(async (g) => {
if (g.granuleId) {
const doc = {
granuleId: g.granuleId,
pdrName: get(payload, 'meta.pdr.name'),
collectionId,
status: get(payload, 'meta.status'),
provider: get(payload, 'meta.provider.id'),
execution,
cmrLink: get(g, 'cmrLink'),
createPdrFromSns(payload) {
const name = get(payload, 'cumulus_meta.execution_name');
const pdrObj = get(payload, 'payload.pdr', get(payload, 'meta.pdr'));
const pdrName = get(pdrObj, 'name');
if (!pdrName) return Promise.resolve();
const arn = aws.getExecutionArn(
get(payload, 'cumulus_meta.state_machine'),
name
);
const execution = aws.getExecutionUrl(arn);
const collection = get(payload, 'meta.collection');
const collectionId = constructCollectionId(collection.name, collection.version);
const stats = {
processing: get(payload, 'payload.running', []).length,
completed: get(payload, 'payload.completed', []).length,
failed: get(payload, 'payload.failed', []).length
};
stats.total = stats.processing + stats.completed + stats.failed;
let progress = 0;
if (stats.processing > 0 && stats.total > 0) {
progress = ((stats.total - stats.processing) / stats.total) * 100;
}
else if (stats.processing === 0 && stats.total > 0) {
createPdrFromSns(payload) {
const name = get(payload, 'cumulus_meta.execution_name');
const pdrObj = get(payload, 'payload.pdr', get(payload, 'meta.pdr'));
const pdrName = get(pdrObj, 'name');
if (!pdrName) return Promise.resolve();
const arn = aws.getExecutionArn(
get(payload, 'cumulus_meta.state_machine'),
name
);
const execution = aws.getExecutionUrl(arn);
const collection = get(payload, 'meta.collection');
const collectionId = constructCollectionId(collection.dataType, collection.version);
const stats = {
processing: get(payload, 'payload.running', []).length,
completed: get(payload, 'payload.completed', []).length,
failed: get(payload, 'payload.failed', []).length
};
stats.total = stats.processing + stats.completed + stats.failed;
let progress = 0;
if (stats.processing > 0 && stats.total > 0) {
progress = ((stats.total - stats.processing) / stats.total) * 100;
}
else if (stats.processing === 0 && stats.total > 0) {
async createGranulesFromSns(cumulusMessage) {
const granules = get(cumulusMessage, 'payload.granules');
if (!granules) return null;
const executionArn = getMessageExecutionArn(cumulusMessage);
if (!executionArn) return null;
const executionUrl = aws.getExecutionUrl(executionArn);
const executionDescription = await StepFunctions.describeExecution({ executionArn });
return Promise.all(
granules
.filter((g) => g.granuleId)
.map(async (granule) => {
const granuleRecord = await Granule.generateGranuleRecord(
granule,
cumulusMessage,
executionUrl,
executionDescription
);
return this.create(granuleRecord);
})
);