简体   繁体   English

谷歌脚本锁是如何工作的?

[英]How does google script lock works?

I am trying to understand how the google script lock works.我想了解谷歌脚本锁是如何工作的。

For better understanding let me create a scenario:为了更好地理解,让我创建一个场景:

Lets suppose there are (script1,script2....script30) 30 simultaneous script running which is the limit from google.让我们假设有 (script1,script2....script30) 30 个同时运行的脚本,这是谷歌的限制。

Now comes another script "script31"现在是另一个脚本“script31”

script31 goes like this: script31 是这样的:

function xyz()
{
  var lock = LockService.getScriptLock();
  
  try { lock.waitLock(10000); } //wait 10 sec

//  Do lots of stuff - read sheet and write in many rows and columns

SpreadsheetApp.flush(); // applies all pending spreadsheet changes
lock.releaseLock();

}

Now my question is how will the script work.现在我的问题是脚本将如何工作。 If there are already 30 script running will it wait for one script to get finished?如果已经有 30 个脚本在运行,是否会等待一个脚本完成?

Lets say out of 30 script now only 29 are running simultaneously.可以说现在 30 个脚本中只有 29 个同时运行。 will my script31 get executed after waiting for 10 sec?等待 10 秒后我的 script31 会被执行吗?

will this condition repeat with Script32, Script33.. and so on who are waiting in line?这种情况会重复出现在 Script32、Script33 等谁在排队吗?

Regardless of what the script does, any script that is executed in excess of 30 simultaneous running scripts will throw an exception:无论脚本做什么,任何超过 30 个同时运行的脚本执行的脚本都会抛出异常:

Exception messages异常信息

If a script reaches a quota or limitation, it throws an exception with a message similar to the following:如果脚本达到配额或限制,它会抛出异常并显示类似于以下内容的消息:

There are too many scripts running simultaneously for this Google user account

This indicates that you have too many scripts executing at once, although not necessarily the same script.这表明您同时执行了太多脚本,尽管不一定是同一个脚本。 Like the exception above, this most commonly occurs for custom functions that are called repeatedly in a single spreadsheet.与上述异常一样,这最常发生在单个电子表格中重复调用的自定义函数中。

Script Locks, on the other hand, only work for simultaneous executions of a defined section of code , between the waitLock and releaseLock methods.另一方面,脚本锁仅适用于在waitLockreleaseLock方法之间同时执行一段已定义的代码 If the other simultaneous executions do not execute code scoped within the lock, they will continue to execute.如果其他同时执行不执行锁定范围内的代码,它们将继续执行。

References:参考:

Quotas for Google Services Google 服务配额

Class Lock Class 锁

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM