Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
Why is this LockService not working as expected when sending email?

I'm using LockService when sending emails, but when multiple users run it at the same time, it throws the error: Service invoked too many times...

Here's some log, showing the failures:

enter image description here

function sendEmail() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  var lock = LockService.getScriptLock();
  try {
    lock.waitLock(3000); // wait 03 seconds for others' use of the code section and lock to stop and then proceed
  } catch (e) {
    Logger.log('Someone has just sent an Email. Try it again 3 seconds later.');
    return HtmlService.createHtmlOutput("<b> Server Busy please try after some time <p>")
    // 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 :("
  }
  
   /*
   Gets certain data from current row. These are used as criteria
   */

    GmailApp.sendEmail(email, "Text", name + " BODY.", { name: 'Diplay Custom Name as Sender' });
    
//Looks for a matching record in another sheet to mark its adjacent column as sent ("Yes")
    for (var n = 0; n < formRespValues.length; n++) {
      if (formRespValues[n][1] == testNo) {
        formRespSheet.getRange('M' + (2 + n)).setValue('Yes');
      }
    }
  }
  SpreadsheetApp.flush(); // applies all pending spreadsheet changes
  lock.releaseLock();
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As @Tanaike pointed out in the comments, a short time within waitLock(timeoutInMillis) or tryLock(timeoutInMillis) may prevent the Lock Service from working as expected.

To ensure the correct functioning, try setting a time that is largely greater than the execution time of your script. If it is less than this, the lock will "open" prematurely, and cause errors such as those outlined in the question.

Documentation :
  • Lock Service
  • Class Lock
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda