Answer the question
In order to leave comments, you need to log in
How to make node-cron control?
Hi all.
The question
is something like this code:
const cron = require('node-cron')
const {Post} = require('../schems/postSchema');
const {User, update} = require('../schems/userSchema')
const cronUpdate = cron.schedule('58 23 * * *', update(),{timezone:'Europe/Kiev'});
const cronSend = cron.schedule('59 23 * * *', send() ,{timezone:'Europe/Kiev'});
async function send(){
const usersArr = await User.find();
const postArr = await Post.find();
if (usersArr){
const day1Users = usersArr.filter(user=>user.status === 'day1');
const day2Users = usersArr.filter(user=>user.status === 'day2');
const day3Users = usersArr.filter(user=>user.status === 'day3');
const day7Users = usersArr.filter(user=>user.status === 'day7');
if (day1Users){
const day1PostArr = postArr.filter(postage=>postage.datePost == 1 )
day1PostArr.map(msg=>{
day1Users.map(user=>{
const send = cron.schedule(`${msg.second} * ${msg.hour} ${user.dateNow+1} * *`,()=>{
bot.sendMessage(user.userId,msg.post , {parse_mode: 'Markdown', disable_web_page_preview: true})
})
})
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question