如何检查 Google App Script 中的函数是否已被其他用户执行? [英] How to check if a function in Google App Script is already being executed by another user?
问题描述
我在 Google App Script 中有一个函数(函数 doGet()),它是从 chrome 扩展程序调用的.每次用户单击 chrome 扩展 popup.html 中的按钮时,都会调用此函数.popup.html 中的这个按钮同时被 30 多个用户点击.我可以检查一下,如果该功能已经被一个用户执行,下一个用户在此之前不能执行它吗?
I have a function (function doGet()) in Google App Script that is being called from a chrome extension. This function is being called everytime a user clicks a button in chrome extension popup.html. This button in popup.html is simultaneously being clicked by 30+ users. Can I place a check that if the function is already being executed by one user, next user cannot execute it till then ?
推荐答案
您可以使用 锁定服务.
锁定服务允许脚本阻止并发访问代码段.当您有多个用户或进程修改共享资源并希望防止冲突.
The Lock Service allows scripts to prevents concurrent access to sections of code. This can be useful when you have multiple users or processes modifying a shared resource and want to prevent collisions.
function doGet(){
var lock = LockService.getScriptLock();
lock.waitLock(10000); // in milliseconds
// Your code
lock.releaseLock();
}
这篇关于如何检查 Google App Script 中的函数是否已被其他用户执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!