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

148
Vistas
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 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