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

398
Visualizações
How do i run same script over and over, with delay between each run?

in order to run a same script multiple times, i currently use ;

For example, i will run something like this

node RocketLaunch.js;node RocketLaunch.js;node RocketLaunch.js

This works great and run my script 3 times back to back. I am wondering is there an easy way i can run these 3 with gap of 1 hour?

Edit - Thank you for the responses, i am new to learning programming so apologize for posting this in JS, since it seems like a non JS question.

More information - The way i want to intend to use it, run this script every 1 hour for lets say 20 hours/times. The entire job takes around 5 minutes after i run the script and i want it to run every hour and do that 5 minutes job.

So perhaps run a command at Bash level, where i can type it 20 times with a delay of an hour. It runs every hour for 20 hours, then i can do the whole thing again.

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

0

This is how I typically do this in bash:

for x in {1..3};
do
node RocketLaunch.js
sleep 3600
done

The {1..3} tells the for loop to do this 3 times, and the sleep function takes the number of seconds as its argument. (3600 = 60 seconds * 60 minutes)

about 4 years ago · Juan Pablo Isaza Relatório

0

Here is the updated answer to your question

Now just run node RocketLaunch.js 1 20 This is the command to tell the script to run every 1 hour for the next 20 hours.

const rockets = {
    launched: () => {
        //your job
        console.log("I'm A Rocket");
    }
};
var arg = process.argv;
const times = Number(arg.slice(2)[1]);
const hours = Number(arg.slice(2)[0])  * 3600000; // to make the hour;

 function launch() {
    var x = 1
    //kick off rockets at script start
    rockets.launched();
    timer = setInterval(() => {
        rockets.launched();
        x++
        if (x === times) {
            clearInterval(timer);
        }
    }, hours) //1000 ms = 1 second
}

launch();

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