太多同时调用50个不同的脚本和触发器 [英] Too many simultaneous invocations 50 different scripts and triggers

查看:99
本文介绍了太多同时调用50个不同的脚本和触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个库存管理系统来跟踪库存.我创建了一个包含50列的电子表格,添加了我们携带的各种不同的库存.我添加了一个公式来减去库存.在特定的单元格中,我有一个脚本,一旦达到阈值,便触发向我发送电子邮件.

I'm setting up an inventory management system to track stock. I have created a spread sheet with 50 columns adding the various different stock we carry. I have added a formula to subtract as the stock becomes used. In a particular cell i have a script and trigger to send me an email once a threshold has been reached.

我遇到的问题是,因为我有50个脚本文件和50个触发器,所以我收到错误消息:同时调用太多:

The problem I'm having is that as I have 50 x script files and 50 x triggers I'm getting the error Too many simultaneous invocations:

下面是我编写的脚本的一个示例,它们都是相同的,但是具有不同的单元格和消息.

below is an example of the scripts I have written, they are all the same but have different cells and message.

function SendEmail1() {
  // Fetch the monthly sales
 var monthSalesRange = 
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("edwards van 
stock").getRange("F5"); 
var monthSales = monthSalesRange.getValue();
var ui = SpreadsheetApp.getUi(); 
// Check totals sales
if (monthSales < 2){
// Fetch the email address
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Set 
Up (do NOT delete)").getRange("B3");
var emailAddress = emailRange.getValues();

// Send Alert Email.
var message = 'FP-C5E-001 ' + monthSales; // Second column
var subject = 'low on stock - place order';
MailApp.sendEmail(emailAddress, subject, message);
}
}

下面是我的触发器-再次都是相同的但功能编号不同.

below are my triggers - again all of them the same but different function number.

触发

推荐答案

答案:

您调用过多,因为您已达到配额.您应该实现某种形式的指数补偿,以限制同时执行和/或触发的次数.

根据Google服务配额文档,您可以 30脚本同时执行,限制为 20个触发器,每个用户,每个脚本:

According to the Quotas for Google Services documentation, you can have 30 simultaneous executions for scripts, with a limit of 20 triggers, per user, per script:

下表列出了截至2018年8月的严格限制.提供以下限制仅是为了帮助您测试脚本.所有限制都可以随时消除,减少或更改,恕不另行通知.

The table below lists hard limitations as of August 2018. The limits shown below are provided solely to assist you in testing scripts. All limits are subject to elimination, reduction, or change at any time, without notice.

Google Cloud文档建议使用指数补偿作为确保IoT设备不会产生过多负载的方法,但是该算法可以应用于存在执行限制的所有计算领域.

Google Cloud documentation suggests using exponential backoff as a way of ensuring IoT devices do not generate excessive load, but the algorithms can be applied to all areas of computing where execution limitations are an issue.

从文档中:

指数退避算法以指数方式重试请求,从而将重试之间的等待时间增加到最大退避时间.例如:

An exponential backoff algorithm retries requests exponentially, increasing the waiting time between retries up to a maximum backoff time. For example:

  1. 提出请求.
  2. 如果请求失败,请等待1 + random_number_milliseconds秒,然后重试该请求.
  3. 如果请求失败,请等待2 + random_number_milliseconds秒,然后重试该请求.
  4. 如果请求失败,请等待4 + random_number_milliseconds秒,然后重试该请求.
  5. 依此类推,直到maximum_backoff时间.
  6. 继续等待并重试最大数量的重试,但不要增加重试之间的等待时间.
  1. Make a request.
  2. If the request fails, wait 1 + random_number_milliseconds seconds and retry the request.
  3. If the request fails, wait 2 + random_number_milliseconds seconds and retry the request.
  4. If the request fails, wait 4 + random_number_milliseconds seconds and retry the request.
  5. And so on, up to a maximum_backoff time.
  6. Continue waiting and retrying up to some maximum number of retries, but do not increase the wait period between retries.

有关算法的更多信息,请参见此处.

Further information of an algorithm can be seen here.

希望对您有帮助!

  • Quotas for Google Services | Apps Script
  • Implementing exponential backoff - Example algorithm

这篇关于太多同时调用50个不同的脚本和触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆