Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
cronjob to go to database node.js

I have this:

cronJob = require('cron').CronJob;

var getTexts = new cronJob( '13 12 * * *', 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")
            }
    
            var arrayOfNumbers = []
            for (var i = 0; i < rows.length; i++) {
                arrayOfNumbers.push(rows[i].PHONE_NUMBER)
            }
            console.log("arrayOfNumbers: ", arrayOfNumbers)
    
            conn.close(function() {
            });
        });
    });
})

What I am doing here is setting a cronjob for 12:13 pm today, which already passed. And within that cronjob function, I go to my database and get the phone numbers, put them in an array, and then try to log the array.

However, at 12:13 pm it didn't go through. I tried this with twillo as well, and it went through. but I cannot figure out what I am doing wrong, or if I can even do what I am looking for. Is this possible

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

According to the cron documentation, the range parameters are:

Seconds: 0-59
Minutes: 0-59
Hours: 0-23
Day of Month: 1-31
Months: 0-11 (Jan-Dec)
Day of Week: 0-6 (Sun-Sat)

So, if you want to run schedule your task on 12:13pm, you need to set your parameters in this way:

const CronJob = require('cron').CronJob;

console.log('Before job instantiation');
const job = new CronJob('* 13 12 * * *', function() {
    const now = new Date();
    console.log('Task runs at', now);
});
console.log('After job instantiation');
job.start();

Note: setting this time without specifying the Seconds parameter, will run the task at every second between 12:13pm ~ 12:14pm internally. So, if you want to run your task once at a specific time, define the Seconds parameter:

const job = new CronJob('0 13 12 * * *', function() {
  // rest of the codes ...
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda