Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
¿Cómo mejorar LockService en este contexto, usando GAS?

Estoy usando LockService para una secuencia de comandos que ubica la fila activa y un par de criterios y, si coinciden, se envía un correo electrónico. Sin embargo, veo que Service invoked too many times frecuencia de lo que pensé que vería, por lo que no estoy seguro de estar usándolo correctamente.

¿Obtener el bloqueo solo después de que se cumplen los criterios es mejor en el futuro, en lugar de hacer que no esté disponible incluso cuando "esa carrera" no cumple con los criterios?

Tiene un activador instalable establecido en función de edición, por lo que lo escaparé lo antes posible antes de obtener el bloqueo, pero aún así...

Aquí está el código:

 function sendEmail() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getActiveSheet(); if (sheet.getName() != 'Todays Tests V2') { return; } const 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('Could not obtain lock after 03 seconds.'); return HtmlService.createHtmlOutput("<b> Server Busy. Please try after some time <p>"); } const testSheet = ss.getSheetByName("Todays Tests V2"); const row = sheet.getActiveCell().getRow(); const col = sheet.getActiveCell().getColumn(); const emailSent = testSheet.getRange(row, 14, 1, 1).getValue(); const sendResults = testSheet.getRange(row, 15, 1, 1).getValue(); const formRespSheet = ss.getSheetByName('Form Responses 1'); const formRespRng = formRespSheet.getRange(2, 13, formRespSheet.getLastRow() - 1, 2); const formRespValues = formRespRng.getValues(); if (ss.getActiveSheet().getSheetName() == testSheet.getSheetName() && row > 5 && col == 15 && sendResults == true) { const email = testSheet.getRange(row, 5).getValue(); const name = testSheet.getRange(row, 3).getValue() + ' ' + testSheet.getRange(row, 4).getValue(); const testNo = testSheet.getRange(row, 2).getValue(); GmailApp.sendEmail(email, "Subject", name + " Msg.", { name: 'Custom Senders Name' }); for (var n = 0; n < formRespValues.length; n++) { if (formRespValues[n][1] == testNo) { formRespSheet.getRange('M' + (2 + n)).setValue('Yes'); } } } lock.releaseLock(); }

Me encantaría entender cómo se puede mejorar esto.

¡Gracias!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!