Google App脚本:Javascript运行时意外退出

斯拉文·库马尔

我编写了一个应用脚本,该脚本将与bigQuery API交互并获取bigQuery结果。

API被击中的次数接近60-70次。在此过程中,有时会收到以下错误消息:

“ JavaScript运行时意外退出”

有人可以帮我吗?

让我知道您是否需要任何其他信息

function fetchTables() {
  var timezone = "GMT+" + new Date().getTimezoneOffset()/60;
  var date = Utilities.formatDate(new Date(), timezone, "yyyy-MM-dd HH:mm");
  Logger.log(date);
  var sheet = SpreadsheetApp.getActive().getSheetByName('Tables');
  var value = sheet.getRange('A1').getValue();

  var projectId = 'corpbi-dev';

  var request = {
    query: 'select table_id from [corpbi-dev:' + value + '.__TABLES__]'
  };
  var queryResults = BigQuery.Jobs.query(request, projectId);
  var jobId = queryResults.jobReference.jobId;

   var rows = queryResults.rows;

  if (rows) {
    // Append the results.
    var data = new Array(rows.length);
    for (var i = 0; i < rows.length; i++) {
      var cols = rows[i].f;
      data[i] = new Array(cols.length);
      for (var j = 0; j < cols.length; j++) {
        data[i][j] = cols[j].v;
      }
    }
  }

  var queries = [];
  var totalbytes = [];
  var timelapsed = [];
  var rowcount = [];
  var jobcode = [];

  var finalSheet = SpreadsheetApp.getActive().getSheetByName('Final Metrics');

  for(var i=1; i<=data.length; i++) {
  var sql = "SELECT stage_loading_query FROM (SELECT stage_loading_query, job_start_time FROM [corpbi-dev:etl_log.job_details] WHERE target_table LIKE '%"+ value + "." + data[i-1]+"%' " +
    "GROUP BY 1, 2 ORDER BY 2 desc) LIMIT 1"

  var request1 = {
    query: sql
  };
  var queryResults1 = BigQuery.Jobs.query(request1, projectId);
  var sql1 = queryResults1.rows;
    //Logger.log(sql1);
 //   break;

  if (sql1) {
    // Append the results.
    var data1 = new Array(sql1.length);
    for (var k = 0; k < sql1.length; k++) {
      var cols = sql1[k].f;
      data1[k] = new Array(cols.length);
      for (var j = 0; j < cols.length; j++) {
        data1[k][j] = cols[j].v;
      }
    }
  }
   queries.push(data1);
     
  }
  //Logger.log(queries.length);
  finalSheet.getRange(2, 1, queries.length).setValues(queries);
//  queries = finalSheet.getRange(2, 1, finalSheet.getLastRow()-1).getValues();
  var endtime = (new Date()).getTime();
  Logger.log(endtime);


  for(var i=1; i<=queries.length; i++) {
    var sqlstmt = queries[i-1];


    try{
      var request2 = {
    query: sqlstmt,
    useLegacySql: true
  };
    var sleepTimeMs = 50000;
  var queryResults2 = BigQuery.Jobs.query(request2, projectId);
       var jobId1 = queryResults2.jobReference.jobId;
      while (!queryResults2.jobComplete) {
        Utilities.sleep(sleepTimeMs);
        sleepTimeMs *= 2;
        queryResults2 = BigQuery.Jobs.getQueryResults(projectId, jobId1);
        //continue;
      }

  var queryDetails = BigQuery.Jobs.get(projectId, jobId1);
  totalbytes.push(queryDetails.statistics.totalBytesProcessed);
  timelapsed.push(queryDetails.statistics.totalSlotMs);
  rowcount.push(queryResults2.totalRows);
}
    catch(e){
      try{
      var request2 = {
    query: sqlstmt,
    useLegacySql: false
  };

    var sleepTimeMs = 50000;
    var queryResults2 = BigQuery.Jobs.query(request2, projectId);
    var jobId1 = queryResults2.jobReference.jobId;
    while(!queryResults2.jobComplete) {
          Utilities.sleep(sleepTimeMs);
        sleepTimeMs *= 2;
        queryResults2 = BigQuery.Jobs.getQueryResults(projectId, jobId1);
       // continue;
      }

  var queryDetails = BigQuery.Jobs.get(projectId, jobId1);
  totalbytes.push(queryDetails.statistics.totalBytesProcessed);
  timelapsed.push(queryDetails.statistics.totalSlotMs);
  rowcount.push(queryResults2.totalRows);
}
      catch(e){
      Logger.log(e);
    }
      Logger.log(e);
    }
  finalSheet.getRange(i+1, 2,).setValue((totalbytes[i-1]/1048576).toFixed(2) + 'MB');
  finalSheet.getRange(i+1, 3,).setValue((timelapsed[i-1]/1000).toFixed(2) + 's');
  finalSheet.getRange(i+1, 4,).setValue((rowcount[i-1]));

  }

}


carlesgg97

Google Apps脚本的V8运行时处于Alpha阶段,这意味着您可能会遇到一些错误/错误。

为了使用稳定的GAS版本,您只需runtimeVersion要将脚本清单中值从V8更改为STABLE

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Google AppEngine:“运行时启动”发生的频率

Google App Engine在Go运行时中找不到文件

在Google App Engine Flex上运行时,使用Java将文件从Google存储桶移动到Google云端硬盘

使用Python运行时在Google App Engine中安装Java

对Google App Engine Go运行时的搜索支持

应用未运行时的Google Awareness Api事件

函数运行时的Google Apps脚本刷新表

将gcloud控制台用于Google App Engine会导致指标发生运行时错误

在运行时本地化Google登录按钮

Google Places API:未捕获运行时异常

Google App Engine-错误(“ python27”运行时仅支持库条目)

从python3.7运行时连接到Google App Engine共享的内存缓存

Google Colab:本地运行时使用

Google Guice运行时依赖项注入

如何加快Google Apps脚本的运行时间?

删除/解决Google表格的运行时限制

Google Apps脚本-分别运行但未结合运行时,两个功能/脚本可以工作

Google Apps脚本的V8运行时

App运行时Google Flutter Google Map API问题

Google Colab无法识别的运行时

如何减少在for循环中使用setValues()和copyto()的Google App脚本的运行时间

Google Deployment Manager运行时策略元数据

Android Google Maps在运行时移动地图

Google js文件未在运行时加载

运行时出现Google.Apis.Http.ConfigurableMessageHandler异常

实时运行时禁用Google Analytics(分析)跟踪

使用Google Guice在运行时注入依赖项

无法在Dockerfile中为Google App Engine中的自定义运行时环境设置环境变量

Google Cloud Storage 运行时错误

TOP 榜单

热门标签

归档