Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
Queuing users for Slides API Batch Update in App Script

My users in App Script read their queue number from a Spreadsheet:

    var array = sessionsSheets.getRange(row, 2, 1, 3).getValues()[0];
    var questionNumber = array[2]; //This is the variable of interest, it is an integer signifying the queue
    sessionsSheets.getRange(`D${row}`).setFormula(questionNumber+1); //This is the updated queue

They then update this queue number as seen above. This method works fine most of the time, but if you take two devices and run the script simultaneously, they both receive the same queue, and the script will halt for one of them because you need a unique queue number later on to use Slides API:

    Slides.Presentations.batchUpdate({'requests': requests}, presentationId);

If promises worked, I would have simply put the Slides API line in a try block, and if an error of duplicity pops up, I would then call the same function recursively, up until overlap doesn't occur. However, promises are not supported in App Script, so what should I try instead?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I found a fix for my special case:

I used ScriptProperties in the Properties Services in App Script. When a user opens the application, he looks for the property of the key with his session's token. If it says busy, he waits and recursively tries the same function, if it says free, he changes it to busy, executes his APIs, then at the end changes it to free again.

Code Snippet:

function queueing(comment,name,token,sessionsSheets,row) {

var properties = PropertiesService.getScriptProperties();
var state = properties.getProperty(token);
if (state==null){
  properties.setProperty(token , `busy@0`);
  posting(comment,name,token,sessionsSheets,row,0);
} else if (state.includes("busy")){
  Logger.log('Gotta wait my turn');
  Utilities.sleep(2000);
  queueing(comment,name,token,sessionsSheets,row);
} else if (state.includes("free")){ 
  var questionNumber = state.split('@')[1];
  properties.setProperty(token , `busy@${questionNumber}`);
  posting(comment,name,token,sessionsSheets,row,questionNumber);
}}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda