代码之家  ›  专栏  ›  技术社区  ›  fairlyMinty

在lambda函数中使用npm模块(ogr2ogr)不会返回任何结果

  •  0
  • fairlyMinty  · 技术社区  · 3 年前

    我正在尝试使用 ogr2gr module 在lambda函数中,但我遇到了一些问题,所以我想看看是否有人试图在lambda函数里使用这个模块?我使用ogr2ogr模块的方式是 .promise() 然而,当我尝试运行我的lambda函数时,我在日志中看不到任何东西。它似乎从来没有兑现过承诺?下面是带有promise的代码:

    let data = await ogr2ogr(path)
                .destination(database)
                .options(['-f "PostgreSQL"', '-nlt PROMOTE_TO_MULTI', 'nln <schemaName>."' + tableName + '"', '-overwrite']).promise();
    console.log(data);
    

    我完全按照文档所述的方式做,但仍然不起作用。我应该指出的是,我曾尝试过这样做

    let ogr = ogr2ogr(path)
                .destination(database)
                .options(['-f "PostgreSQL"', '-nlt PROMOTE_TO_MULTI', 'nln <schemaName>."' + tableName + '"', '-overwrite']);
    console.log(ogr);
    

    我实际上在日志中看到了EventEmitter:

    EventEmitter {
      _inPath: '<path_of_file>',
      _onStderr: [Function (anonymous)],
      _driver: {},
      _args: [],
      _timeout: 15000,
      _format: 'GeoJSON',
      _skipfailures: false,
      _testClean: [Function (anonymous)],
      _destination: <database information>,
      _options: [
        '-f "PostgreSQL"',
        '-nlt PROMOTE_TO_MULTI',
        'nln useradministration.tableName',
        '-overwrite'
      ]
    }
    

    但如果我尝试按照文档所述进行回调,请使用 .exec() 函数,我没有看到任何输出:

            let ogr = ogr2ogr(path)
                .destination(database)
                .options(['-f "PostgreSQL"', '-nlt PROMOTE_TO_MULTI', 'nln <schemaName>."' + tableName + '"', '-overwrite']);
            console.log(ogr);
            
            ogr.exec(function (er, data) {
              if (er) {
                console.error(er);
              }
              console.log(data);
            });
    

    老实说,我在这一点上很困惑,不知道该怎么办。非常感谢任何帮助,比如如果有人遇到类似的问题,或者解释一下为什么promise或callback在lambda函数中有效。

    0 回复  |  直到 3 年前
        1
  •  0
  •   fairlyMinty    3 年前

    事实证明,我的lambda超时为3秒,promise花费的时间超过3秒,导致lambda超时,我在日志中没有看到任何结果。

    推荐文章