I use the cron library to run the following snippet of code
pepinosModelo.find()
.exec()
.then(pepinos => {
pepinos.forEach(pepino => {
let frecuencia = pepino.frecuente();
let nuevoTrans = [{
chocolate:true,
abena:"de dos a tres porcines",
lsd: "No aplica"
}];
nuevoTrans.push({
chocolate:false,
coco:"Completo",
lsd: "Aplica"
});
return TransModel.create(nuevoTrans)
.then((trans) => {
fumadorModelo
.update({
pepino: pepino._id
}, {
'comprador': false,
'nuevaDocis': zero
})
.exec()
.then((usuario) => {
pepino.cambio += frecuencia;
pepino.balance = zero;
pepino.puntos = zero;
return pepino
.save()
.then(() => {
console.log(´fin actualizacion usuario ciclo ${usuario}´);
});
});
});
});
});
and to run it I do it this way
try{
// let when = '00 30 11 1-2 * *';
// let timeZone = '';
let when = '* 10 * * * *';
new CronJob({
cronTime: when,
onTick: cronFn,
start: true,
// timeZone
});
}catch(err) {
console.error('something happening with cron:', err);
}
- The issue is that I'm not so sure if you run the task several times or just once
- Could this saturate the server depending on the number of documents in the cucumber collection?
- What happens if you fail to update or create a document