When Google Apps Script takes time to process doPost, doPost was called again (after 2 minutes), so I tried to prevent it from re-entering with LockService getUserLock and getScriptLock, but I could get the lock. If I POST to compete from other tabs and windows, I can't get the lock. Where's the problem?
function doPost(){
// var lock = LockService.getUserLock();
var lock = LockService.getScriptLock();
var success=lock.tryLock(3);
If(!success){// If the lock is not released within 3 seconds, it is determined that the previous processing has not been completed.
console.error('doPost was called while processing doPost.');
outHtml=HtmlService.createTemplateFromFile("Wait a minute.");
return outHtml.evaluate();
}
try{
Utilities.sleep (180000);
}
US>finally
lock.releaseLock();
}
In the end, userProperties recorded the execution state (processed, accepted) as the user's property so that it did not start new processing when called during processing. We also recorded the start time and accepted execution after a certain period of time.
© 2024 OneMinuteCode. All rights reserved.