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

166
Visualizações
Running function every minute and sending message

I have this function:

    var getTexts = new cronJob( '*/1 * * * *', function(){
    var viewConformationEmails = "select * from clients";
    ibmdb.open(ibmdbconn, function(err, conn) {
        if (err) return console.log(err);
        conn.query(viewConformationEmails, function(err, rows) {
            if (err) {
                console.log(err);
            } else if (!err) {
                console.log("Success")
            }

            
            for (var i = 0; i < rows.length; i++) {
                // arrayOfNumbers.push(rows[i].NAME)
                // arrayOfNumbers.push(rows[i].PHONE_NUMBER)
                // arrayOfNumbers.push(rows[i].HOUR)
                // arrayOfNumbers.push(rows[i].MINUTE)
                var minute = rows[i].MINUTE;
                var hour = rows[i].HOUR;
                console.log(rows[i])
                var stringg = rows[i]["MINUTE"] + " " + rows[i]["HOUR"] + " * " + "* " + "*"


                var textJob = new cronJob( stringg, function(){
                    client.messages.create( { to:'xxx', from:'yyy', body:'Hello! Hope you’re having a good day!' }, function( err, data ) {});
                  },  null, true);
            }

            conn.close(function() {
            });
        });
    });
}, null, true)

what it is supposed to do is run a cronjob every 1 minute, which gets all the results from my clients table. I then loop through each result, and if it is the current time and it mathces the time in the database, then it sends the message. however, it runs the first cronjob at each minute of the day, and then let's say my etxt is supposed to go our at 9:15, then it can't get there fast enough, because it is still going through the first cronjob iteration. That's my guess, but i'm not 100% sure and i cannot figure out why. Can someone help?

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

0

Figured it out by doing this:

var getTexts = new cronJob( '45 * * * * *', function(){

what it does is run the cronjob every 45 seconds, which then will send out the text message at the designated time. works perfect, so far ...

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