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

150
Visualizações
Using my own logic to run cron job only once at the specified date/time. Will the cron listener continue to run though?

I am using and new to node-cron. So I was able to set and run a function on the scheduled time/date I specified. What I read is that we cannot set a year in cron jobs, so I made my code like this.

const cron = cronTest.schedule(
  '39 20 29 March *',
  () => {
    console.log('successfully ran');
  },
  { scheduled: false }
);

if (new Date().getFullYear() == req.body.scheduledYear) {
  cron.start();
}

So in the future date March 29, 8:39 PM, it will output 'successfully ran' in the console, if the current year is equal or now equal to the year set in scheduledYear variable.

My question is, after all that, on the next March 29, 8:39 PM on the following year, will my cron job be running again? If yes, I know it will never output my console.log which is what I wanted in the first place, but the concern is if there is still some listener or watcher running in the background on the server waiting for another March 29, 8:39 PM to come up?

How would I know if there are cron related events running in my server? Is my code above fine, and will not cause performance issues? I'm not so familiar how server works, but please let me know if what I'm doing here is very wrong.

Thanks.

about 4 years ago · Juan Pablo Isaza
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