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

307
Visualizações
Call setTimeout at Firebase Cloud Functions onCreate

I'm using following code in order to call a function with setTimeout, but I'm not really into JS and Firebase Cloud Functions.

However my logs are showing following error: "Function returned undefined, expected Promise or value" "Exception from a finished function: Error: Value for argument "documentPath" is not a valid resource path. Path must be a non-empty string."

This is my code:

function updateDoc(id) {
    admin.firestore().collection('Orders').doc(id).update({status: 2}).then(() => {
        console.log("Document successfully updated!");
    })
    .catch((error) => {
        console.error("Error updating document: ", error);
    });
}

exports.updateField = functions.firestore
    .document('/Orders/{id}')
    .onCreate((snapshot, context) => {
        const id = context.params.id;
      setTimeout(updateDoc.bind(id), 30000) 
    });

Thanks for any kind of help.

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

0

There are several problems with your code:

  • You should pass the id as a "simple" argument when calling the updateDoc()method.
  • You need to return a Promise or a value in your Cloud Function to indicate to the Cloud Function platform that the Cloud Function has completed. You'll find more details in the doc and in this video series.

In addition, using setTimeout in a Cloud Function shall be done with care, see these SO answers. You could probably re-architect your solution in order to avoid the setTimeout. If you share more info on why you use it, the community may help you.

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