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

220
Visualizações
How to download a file through FTP with a firebase function?

QUESTION:

Unfortunately, my function finishes execution within seconds instead of executing in full. This is apparently due to the fact that listeners are declared to stream the data: they are not promises I can await to my knowledge.

How may I have my firebase function execute in full ?


CODE:

exports.fifteenMinutesData = functions
.runWith(runtimeOpts)
.pubsub
.schedule('*/15 * * * *')
.timeZone('Etc/UTC')
.onRun((context) => {
    return (async() => {
        try {

            const Client = require('ftp');
            const c = new Client();
            
            c.connect({
                host: "...",
                user: "..."
            });
            
            c.on('ready', async function () {
                c.get('text.txt', async function (err, stream) {
                    if (err)
                        throw err;
                    var content = '';
                    stream.on('data', function (chunk) {
                        content += chunk.toString();
                    });
                    stream.on('end', function () {
                        (async () => {

                            try {
                                let data = content;

                                //etc....
                            }
                            catch(err) {
                                console.log("ERR: "+err);
                            }
                        })()
                    })
                })
            })
        }
        catch(err) {
            console.log("ERR: "+err)
        }
    })()
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You will need to promisify the result so the module is aware the value is asynchronous. Currently, your callback is not informing the module of anything so the execution exits immediately, you will want a format like

exports.fifteenMinutesData = functions
.runWith(runtimeOpts)
.pubsub
.schedule('*/15 * * * *')
.timeZone('Etc/UTC')
.onRun((context) => new Promise((resolve, reject) => 
{

});

Where you call resolve(data); for the success path and reject(err); for all error execution paths.

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