服务在短时间内被调用太多次:exec qps。 -Google表格

时间:2018-09-25 09:08:50

标签: google-apps-script google-sheets custom-function

我一直在使用自定义函数将简单的数学分解为可读的JavaScript,但是出现以下错误:

  

服务在短时间内被调用太多次:exec qps。两次通话之间尝试Utilities.sleep(1000)。 (第0行)。

我尝试了随机睡眠,但这没有帮助。我的功能如下:

function conversationGrowthRate(clientCount, initialGrowthRate, conversationCount) {  
  //Utilities.sleep(Math.random() * 30000);
  for (var i = clientCount; i > 10; i--) {
    if (initialGrowthRate > 0) {
      conversationCount += initialGrowthRate
      initialGrowthRate -= 0.000003
    }
  }
  return conversationCount;
}

function conversionGrowth(clientCount, conversationCount, initialConversionRate, conversionGrowthRate, maxConversionRate, coversPerBooking, initialConversationGrowthRate, initialConversationCount) {
  //Utilities.sleep(Math.random() * 30000);
  if (clientCount <= 50) {
    return coversPerBooking * conversationCount * initialConversionRate;
  }
  else {
    var firstFiftyClientConversations = conversationGrowthRate(50,initialConversationGrowthRate, initialConversationCount)*30*50; //~30
    var additionalConversionGrowthRate = (clientCount-50) * conversionGrowthRate;
    var totalConversionRate = initialConversionRate + additionalConversionGrowthRate;
    var additionalClientConversations = conversationGrowthRate(clientCount-50, initialConversationGrowthRate, initialConversationCount) * 30 * (clientCount-50);
    if (totalConversionRate < maxConversionRate) {
      return coversPerBooking * ((firstFiftyClientConversations * initialConversionRate) + (additionalClientConversations * totalConversionRate));
    }
    else {
      return coversPerBooking * (conversationCount * maxConversionRate); 
    }
  }
}

function salesProductivity(currentExecs, prevMonthExecs, prevTwoMonthExecs, prevThreeMonthExecs, prevFourMonthExecs, salesPerExecPerMonth) {
  //Utilities.sleep(Math.random() * 30000);
  var firstMonthHires = currentExecs - prevMonthExecs;
  var secondMonthHires = prevMonthExecs - prevTwoMonthExecs;
  var thirdMonthHires = prevTwoMonthExecs - prevThreeMonthExecs;
  var fourthMonthHires = prevThreeMonthExecs - prevFourMonthExecs;
  var longerHires = prevFourMonthExecs;

  return (secondMonthHires * (0.33 * salesPerExecPerMonth)) + (thirdMonthHires * (0.66 * salesPerExecPerMonth)) + (fourthMonthHires * (1 * salesPerExecPerMonth)) + (longerHires * salesPerExecPerMonth);
}

在它开始工作之前,我什么也没改变。

2 个答案:

答案 0 :(得分:1)

这应该适用于任何达到使用配额的Google服务。

while(true) {
  try {
    return '<whatever's hitting the quota>';
  }
  catch(error) {
    Utilities.sleep(1000);
  }
}
  • 它不会放弃
  • 除非需要,否则不会造成延迟

答案 1 :(得分:0)

Google表格通过名为exec的服务远程运行自定义功能。如果对任何自定义函数的调用“过多”(根据一些未记录的配额,或者至少我没有找到任何此类文档),将发出此错误。

如果由于许多单元正在调用自定义函数而导致调用发生,我不知道Utilities.sleep(milliseconds)有什么帮助,因为exec会在sleep之前被调用(实际上,它会将是exec,将直接或间接调用sleep

正如一些评论所提到的那样,将函数转换为接受范围并返回数组(并更改工作表以容纳所述函数)是一种方法(直到Google添加更智能的节流)。