google-apps-script - '异常: Too many simultaneous invocations: Spreadsheets' - Is it because I am opening spreadsheets in a loop?

标签 google-apps-script google-sheets simultaneous simultaneous-calls

我收到错误:

Exception: Too many simultaneous invocations: Spreadsheets

我看过quota page它没有提及任何有关打开电子表格的信息。我假设同时调用是指某些事情与其他事情同时发生,但我假设我的脚本仅从单个触发器运行,将逐一完成每个进程,因此不应该有任何内容同时发生。我完全错了吗?我看了Does google app script simultaneous executions quota apply for the script in question or for each users?但我还是不知道它是关于什么的。

我尝试手动运行脚本,它似乎可以很好地处理每条记录,然后在到达最后一行(已正确处理)后,它只是卡在最后。

我的代码如下:

function importDataFromSAN() {

  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getActiveSheet();
  const data = sheet.getDataRange().getValues();
  data.shift();

  const formSheet = SpreadsheetApp.openById('MyID');
  const formData = formSheet.getDataRange().getValues();
  formData.shift();

  data.forEach(row => {

    const fileURL = row[41];
    const studentNumber = row[10];

    if (fileURL === '') {

      console.log('No form');

    }
    else {
      const file = SpreadsheetApp.openByUrl(fileURL);

      const medConditions = file.getRange('B49');
      const currentSituation = file.getRange('B54');

      const matchNumber = formData.filter(a => a[4] === studentNumber);

      matchNumber.forEach(a => {

        const healthNeeds = a[10];
        const learningDifficulty = a[18];
        const riskAssessment = a[27] + ' ' + a[29] + ' ' + a[31] + ' ' + a[33] + ' ' + a[35] + ' ' + a[37] + ' ' + a[39] + ' ' + a[41] + ' ' + a[43] + ' ' + a[45] + ' ' + a[47] + ' ' + a[49];
        const outsideAgencies = a[73] + ' ' + a[75] + ' ' + a[77] + ' ' + a[79] + ' ' + a[81];

        medConditions.setValue('Health Needs - ' + healthNeeds + '\nLearning Difficulties - ' + learningDifficulty);
        currentSituation.setValue('Risk Assessment Details - ' + riskAssessment + '\nOutside Agencies Details - ' + outsideAgencies);
      });
    }
  });
}

我厌倦了手动运行脚本。我原以为它会在达到一定数量后失败,但它完成了所有行,然后在最后挂断了。

编辑:经过漫长的等待,它在手动运行上完成。我确实与此脚本同时运行了不同项目中的不同脚本,这是否会导致问题,或者每个项目和其他项目的限制没有影响?

最佳答案

通常,错误 Exception: Too muchsimulates: Spreadsheets 是在短时间内对电子表格发出太多请求时引起的,这不仅可能是由多少次引起的该脚本是由对电子表格发出请求的时间触发的。此消息类似于 documented 的其他异常消息。 。问题不在于项目,而在于您访问特定电子表格的次数。

就您的情况而言,解决问题的最佳方法是分析如何减少电子表格上的工作量,因为您使用的是触发器,因为这意味着该函数将在每次触发器发生事件时运行已满足。

关于google-apps-script - '异常: Too many simultaneous invocations: Spreadsheets' - Is it because I am opening spreadsheets in a loop?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74361502/

相关文章:

php - 使用 PECL HTTP 类在 PHP 中进行并行 HTTP 请求 [答案 : HttpRequestPool class]

ios - 同时并以顺序方式播放/暂停/停止多个音频文件

google-apps-script - 通过 Google Apps 脚本部署和使用 Google 表格插件

javascript - 将新的 Google Sheets 数据附加到 BigQuery 表中

google-apps-script - 有没有办法从电子表格中的给定网址生成面包屑?

javascript - 如何在 Google Apps 脚本中使用 locale moment.js?

openssl - OpenSSL 是否允许每个进程使用多个 SSL_CTX,一个 SSL_CTX 用于服务器 session ,另一个 SSL_CTX 用于客户端 session ?

javascript - 在哪里/如何设置循环增量并仅在找到条件时更新数组?

javascript - GAS 找到所有匹配的值,然后通过电子邮件将它们一起发送

node.js - 使用 Google API 在工作表中设置数据时,Google 表格会自动更改日期格式