How to use the @cumulus/ingest/granule.selector function in @cumulus/ingest

To help you get started, we’ve selected a few @cumulus/ingest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nasa / cumulus / tasks / sync-granule / index.js View on Github external
const duplicateHandling = duplicateHandlingType(event);

  // use stack and collection names to suffix fileStagingDir
  const fileStagingDir = path.join(
    (config.fileStagingDir || 'file-staging'),
    stack
  );

  if (!provider) {
    const err = new errors.ProviderNotFound('Provider info not provided');
    log.error(err);
    return Promise.reject(err);
  }

  const IngestClass = granuleSelector('ingest', provider.protocol);
  const ingest = new IngestClass(
    buckets,
    collection,
    provider,
    fileStagingDir,
    forceDownload,
    duplicateHandling
  );

  return download(ingest, downloadBucket, provider, input.granules)
    .then((granules) => {
      if (ingest.end) ingest.end();
      const output = { granules };
      if (collection && collection.process) output.process = collection.process;
      if (config.pdr) output.pdr = config.pdr;
      log.debug(`SyncGranule Complete. Returning output: ${JSON.stringify(output)}`);
github nasa / cumulus / tasks / discover-granules / index.js View on Github external
async function discoverGranules(event) {
  const protocol = event.config.provider.protocol;
  const Discoverer = granule.selector('discover', protocol);
  const discoverer = new Discoverer(event);

  try {
    const granules = await discoverer.discover();
    log.info(`Discovered ${granules.length} granules.`);
    return { granules };
  } finally {
    if (discoverer.connected) await discoverer.end();
  }
}
github nasa / cumulus / cumulus / tasks / sync-granule / index.js View on Github external
module.exports.handler = function handler(_event, context, cb) {
  try {
    const event = Object.assign({}, _event);
    const buckets = get(event, 'resources.buckets');
    const collection = get(event, 'collection.meta');
    const granules = get(event, 'payload.granules');
    const provider = get(event, 'provider');

    if (!provider) {
      const err = new errors.ProviderNotFound('Provider info not provided');
      log.error(err);
      return cb(err);
    }

    const IngestClass = granule.selector('ingest', provider.protocol);
    const ingest = new IngestClass(event);

    return download(ingest, buckets.internal, provider, granules).then((gs) => {
      event.payload.granules = gs;

      if (collection.process) {
        event.meta.process = collection.process;
      }

      if (ingest.end) {
        ingest.end();
      }

      return cb(null, event);
    }).catch(e => {
      if (ingest.end) {