Kosaaaaa
Kosaaaaa

Reputation: 185

Script lock for different users google app maker

i'm struggling with problem of running script by 2 or more users in the same time. Script adds data to spreadsheet and creates folders in google drive. I've tried using Lockservice, but it didn't work. And I've made my own 'Lock' which change value in sheet and when this Busy status is true script won't run, but it changes too slow.

function thisRunsClient(){
    var lock = LockService.getScriptLock();
    if(lock.hasLock()){return 'END')};
    else{
    lock.tryLock(10000)};
   //rest of code
}

Upvotes: 1

Views: 70

Answers (1)

J. G.
J. G.

Reputation: 1832

What I use is

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 copy lock after 20 seconds.');
        return;
    }
//REST OF CODE

I'm not sure what you are trying to do with the haslock there, it looks to me like if you get the lock you immediately end the function, which doesn't seem like what you want to do.

Upvotes: 1

Related Questions