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

269
Visualizações
How to clean up /tmp files after cloud function sends response?

I have a Google Cloud Run container acting as an express server.

End users upload files into a temporary directory, I process them, and send a file back.

I'd like to clean up the original upload (and other intermediary files) so that they don't take up memory.

But the docs say that code after the response isn't guaranteed to execute.

So how/where do I delete the temp files?

Here's a simplified example:

// process user upload, then:
res.download('someFile');
fs.unlinkSync('someFile') // not guaranteed to run;
return null;
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

With Cloud Run, you can use the CPU always ON feature. It's not the cheapest, but it specially designed to continue to work in the background, even if there isn't handled request. And that, up to 15 minutes after the latest response send and if there isn't new request on the instance.

If you use Cloud Functions 1st gen, I can recommend you to clean the /tmp dir when you start the processing of your Cloud Functions, not at the end.

Note: Cloud Functions 2nd gen is similar to Cloud Run


EDIT 1

You can play with the system and hack it to implement what you want.

After sending the response back, you can create your background process that delete the specific file in /tmp.

Because you have no longer access to CPU, that instruction will be on hold.

BUT, when the next request is received, the CPU is coming back to life for the whole instance (not for the current request) and therefore your background process will resume and delete the files.

If the instance doesn't receive a new request for the next 15 minutes, it will be offloaded, and the memory (and your files) swiped automatically!

over 4 years ago · Santiago Trujillo 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