Answer the question
In order to leave comments, you need to log in
What is the correct way to use LockService in Google Apps Script?
Good afternoon. There is a code that accepts post and get requests and inserts the transferred data into the table. So that the data is not overwritten, I added a queue:
var lock = LockService.getPublicLock();
lock.waitLock(30000);
//код
lock.releaseLock();
Answer the question
In order to leave comments, you need to log in
The waitLock method throws an exception, handle it.
var lock = LockService.getPublicLock();
try {
lock.waitLock(30000);
return success();
} catch (err) {
Logger.log('Could not obtain lock after 30 seconds.');
return failure();
}
var lock = LockService.getPublicLock();
var success = lock.tryLock(30000);
if (!success) {
Logger.log('Could not obtain lock after 30 seconds.');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question