首页 > 编程语言 >node.js 定时任务/重复任务

node.js 定时任务/重复任务

时间:2023-02-14 10:37:50浏览次数:86  
标签:node 12 const schedule rule js 任务 执行


文章目录

  • ​​git​​
  • ​​参数​​
  • ​​定时任务​​
  • ​​每天0点执行一次数据统计任务​​
  • ​​每半个小时执行一次数据统计任务​​
  • ​​重复任务​​
  • ​​指定执行时间氛围​​
git

​https://github.com/node-schedule/node-schedule#readme​

const schedule = require('node-schedule');
参数

node.js 定时任务/重复任务_定时任务


可见第一个参数决定绅什么时候执行 可以是 string number 重复规则 重复时间区域 重复对象列表 Date 十分全面可适应大部分常见场景

定时任务

每天0点执行一次数据统计任务
schedule.scheduleJob('0 0 0 * * *', function () {
//.....
})
每半个小时执行一次数据统计任务
schedule.scheduleJob('0 0 0 0 30 *', function () {
//.....
})

重复任务

指定执行时间氛围

例如 允许 7点到12点执行

const rule = new schedule.RecurrenceRule();
rule.hour = [7,8,9,12];

如上实际效果会是 在7点到12点期间一直执行
7点到12点每1个小时的0分0秒执行一次

const rule = new schedule.RecurrenceRule();
rule.hour = [7,8,9,12];
rule.minute = 0;
rule.second = 0;

7点到12点每半个小时执行一次

const rule = new schedule.RecurrenceRule();
rule.hour = [7,8,9,12];
rule.minute = [0,30];
rule.second = 0


标签:node,12,const,schedule,rule,js,任务,执行
From: https://blog.51cto.com/u_15964288/6055861

相关文章

  • node.js 发送邮件
    constnodemailer=require("nodemailer");lettransporter=null;asyncfunctioncreateMailServer(){transporter=nodemailer.createTransport({host:"......
  • js 选中文字修改:裁剪,加粗... 获得选中内容
    使用以下两个api​​MDNSelectionAPI​​​​MDNRangeAPI​​需要APIconstRange=useCallback(()=>{constselObj=window.getSelection();if(!selObj)......
  • 在next.js中使用styled-component以及全局主题切换
    文章目录​​使styled-component像SPA中使用​​​​step1安装插件​​​​step2根目录下创建`.babelrc`​​​​step3创建`page/_document.js`自定义Document​​​......
  • JS实现下载文件
    最近需要下载一些视频,数量不算多,百十个,动态加载比较多,写爬虫比较麻烦,想想不如直接做个书签JS直接点点鼠标下载了。第一个:直接打开链接javascript:(function(){varuri_e......
  • Python_json类方法
    Python_json类方法importrequestsimportjsonheaders={"User-Agent":"Mozilla/5.0(LinuxAndroid6.0Nexus5Build/MRA58N)AppleWebKit/537.36(KHTML,l......
  • 任务二
    下载安装php小皮面板,安装后打开PHPStudy小皮面板:https://public.xp.cn/upgrades/phpStudy_64.zip1.启动MySQ和Nginx​点击网站,点击管理,打开根......
  • node增删改查
    文章目录​​INSERT​​​​SELECT​​​​DELETE​​​​UPDATE​​INSERTconstapp=express();app.use(express.json());//forparsingapplication/jsonapp.use(expr......
  • node mysql 增删改查 demo
    前端原生jsJquery后端Node数据库MySQL​​​http://hongbin.xyz:8080/​​​​github仓库​​​​演示视频地址​​node增删改查TODO:删除用户数据库需要触发器将......
  • js 0.1+0.2 !== 0.3 简单解决方案
    exportconstround=number=>{constgetFloat=number.toString().split(".");if(getFloat.length===1){returnnumber;}constfloatLength=getFloa......
  • Node.js 处理 File
    Node.js处理Filefs模块常规使用运用递归遍历目录树创建文件和目录读写文件path模块对于file的理解,此处fs模块Node.js提供了处理文件系统的内置模块:f......