📜  谷歌应用脚本锁定服务 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:24.105000             🧑  作者: Mango

代码示例1
// BEGIN - start lock here

var lock = LockService.getScriptLock();
try {
    lock.waitLock(30000); // wait 30 seconds for others' use of the code section and lock to stop and then proceed
} catch (e) {
    Logger.log('Could not obtain lock after 30 seconds.');
    return HtmlService.createHtmlOutput(" Server Busy please try after some time 

") // In case this a server side code called asynchronously you return a error code and display the appropriate message on the client side return "Error: Server busy try again later... Sorry :(" } // note: if return is run in the catch block above the following will not run as the function will be exited // Do lots of stuff - ie apply dynamic background colors based on previous entries colors, define the target range and set values, set data validations lock.releaseLock(); // END - end lock here