Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!