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

167
Visualizações
Continuously check whether or not a date has been expired

Here's our scenario:

We are using node w/ express for our web app and we need to create a background process that continuously checks the created date on multiple posts and when they expire. These expired dates are set by the user so the posts expire at different rates. When the date expires, our app should be triggering specific events.

We are considering using a "setInterval" but wasn't sure if this is the best long-term solution.

Is there a solution to have node continuously check whether or not a date has been expired? Upon expiring, the posts must trigger specific functions.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

There are two ways to do this:

1) use moment lib like this:

var date = moment("2013-03-24")
var now = moment();

if (now > date) {
   // date is past
} else {
   // date is future
}

2) use node-schedule like this:

var schedule = require('node-schedule');
var futureDate = new Date(new Date().getTime() + 60 * 60 * 24 * 1000); // This is 24 hours from *now*

var j = schedule.scheduleJob(futureDate, function(){
  console.log('Do your work here.');
});
over 4 years ago · Santiago Trujillo Relatório

0

Im not sure about your code but if u can catch the event when the users post, the easy way would be

setTimeout(whateverYouHaveTodo, expireTimeInMilliseconds);

each time an event is triggered.

And if you need to cancel the timeouts in the future, what i do personally is put the timeouts in a json object with the key as a unique id which you could identify the event specifically

over 4 years ago · Santiago Trujillo 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