Scheduled tasks

  • You can configure the timer in ndsk.config.js
 module.exports = (isPro)=>{
      return {
          server:{
              plugins:{
                cron:[
                    {
                        name:"job",                        //Task Name
                        time:'*/1 * * * * *',              //Expression, here it means executing once per second
                        timezone:"Asia/Shanghai",          //Time Zone
                        scheduled:true,                    //Task status, true means started
                        handler:(server)=>{                //Handler, server from the server
                            // const collection = server.mongo.client.db('ndsk').collection('xxx');
                            // fetch('http://127.0.0.1:3000/api').then(async res=>{
                            //     console.log(await res.json())
                            // })
                            console.log(`this is a cron`)
                        }
                    }
                ]
              }
          }  
      }
  }

cron

  • Task queue, an array, allows the following parameters

    • name Task Name

    • time Task expressions, which you can view here

    • timezone Time Zone

    • scheduled Task status, true means started, false means closed

    • handler A function, server server properties, see documentation here

  • Note: After the framework is processed, a single server will not repeat tasks when multi-threading is enabled with pm2. In the case of multiple server clusters, you should configure timers separately to avoid repeated execution

Next

Mongodb