Issue with LockService object

33 views
Skip to first unread message

FRANCOIS RENARD

unread,
Jun 3, 2024, 5:52:08 AM6/3/24
to Google Apps Script Community

Hi,

I have a trigger timebased (every fifteen minutes), and I want to make sure that script triggered is completly done before another trigger starts to run.

So I'm using getDocumentLock - and WaitLock fucntion()
It works most of  the time, but after a while, i don't know why, waitock is ok but a script is  still running !

Thanks for your help !

Here is my code 

// every 15 minutes
function trigger_run()
{

  let b_ok = true;
  let lock = LockService.getDocumentLock();

  try
  {
    lock.waitLock(2000);
    Run_script();
    SpreadsheetApp.flush();      
  }
  catch (e)
  {
    Logger.log(e);
    b_ok=false;
  }
  finally
  {
    if (lock.hasLock()) lock.releaseLock();
    return b_ok;
  }
}

Reply all
Reply to author
Forward
0 new messages