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

149
Visualizações
How can i update values stored in map to database after every 1 hour while synchronizing incoming requests on route which updates map continously

I am facing a problem to update the values stored in map to database because the map is updating continously due to incoming requests on the route and at the same time I want to update values in database periodically with the help of map. How to synchronize both the operations?

const url_count = new Map();

async function update_count(){
 
    // update value in mongodb 
    
}
app.get('/teeny/:code', async (req, res) => {
    try {
        const url = await Link_URL.findOne({
            _id : req.params.code
        })
        if (url) {
          if(url_count.has(req.params.code)){
            const val = url_count.get(req.params.code);
            url_count.set(req.params.code,val+1);
            update_count();
          }
          else{
              url_count.set(req.params.code,1);
          }  
            return res.redirect(url.URL);
        } else {
            return res.status(404).json('No URL Found')
        }
    }
    catch (err) {
        console.error(err)
        res.status(500).json('Server Error')
    }
})
cron.schedule('* * 1 * *', update_count);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could use Later for a simple solution... here you would be collecting all those values and then insert them at a specified time that you specified in later..

For something heavier, you could go for Bull or for Rabbot

If you want to kill a lion, go for Node-Celery... but make sure to have python installed.

Basically, all you need is a queuing system to collect[in a queue] all those tasks that you want to save later...

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