Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.timeTask = function () {
// 两个时间规则,降低爬虫频率,提高成功率
let ruleChina = new schedule.RecurrenceRule();
let ruleAll = new schedule.RecurrenceRule();
let ruleLanguage = new schedule.RecurrenceRule();
ruleChina.hour = [1];
ruleChina.minute = 0;
ruleAll.hour = [2];
ruleAll.minute = 0;
ruleLanguage.hour = [3];
ruleLanguage.minute = 0;
// 每隔6小时执行一次, 奇数小时
schedule.scheduleJob(ruleChina, async function () {
console.log('China most followers定时任务开始执行!', moment().format('YYYY-MM-DD HH:mm:ss'));
// 获取 100 most followers of china
html: html
};
transporter.sendMail(mailOptions, (error, info = {}) => {
if (error) {
console.log(error);
// sendMail(HtmlData); //再次发送
return false;
}
console.log("邮件发送成功", info.messageId);
console.log("静等下一次发送");
});
}
//每日发送时间
let EmailHour = 8;
let EmialMinminute= 20;
let rule = new schedule.RecurrenceRule();
// 0, 1, 2, 3, 4, 5, 6
// Sunday, mon, tue, th, f, f s
rule.dayOfWeek = [0, new schedule.Range(1, 6)];
rule.hour = EmailHour;
rule.minute = EmialMinminute;
console.log('NodeMail: 开始等待目标时刻...')
let j = schedule.scheduleJob(rule, function() {
console.log("执行任务");
getAllDataAndSendMail();
});
/**
* 定时任务
**/
var schedule = require("node-schedule");
var conf = require('../config.js');
//第一次开启时先跑一遍逻辑
SyncFans();
SyncCard();
SyncShop();
/**
* 定时拉取粉丝信息(每天6:00)
**/
var ruleFans = new schedule.RecurrenceRule();
ruleFans.dayOfWeek = [0, new schedule.Range(1, 6)];
ruleFans.hour = 6;
ruleFans.minute = 0;
//var fansTimes = [];
//for (var j = 0; j < 60; j = j + 1) {
// fansTimes.push(i);
//}
//ruleFans.minute = fansTimes;
var fansJob = schedule.scheduleJob(ruleFans, function () {
SyncFans();
});
/**
* 同步粉丝
**/
function SyncFans() {
/*
* 规则4 每天凌晨1点和中午13点定时任务
* */
let rule4 = new schedule.RecurrenceRule();
rule4.hour = [1,13];
rule4.minute = 0; //必填
/*
* 规则5 凌晨3点的定时任务
* */
let rule5 = new schedule.RecurrenceRule();
rule5.hour = 3;
rule5.minute = 0; //必填
/*
* 规则6 每两个小时一次的定时任务
* */
let rule6 = new schedule.RecurrenceRule();
// rule6.hour = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23];
// rule6.hour = [];
rule6.hour = [0,2,4,6,8,10,12,14,16,18,20,22];
rule6.minute = 0; //必填
// let i6 = 0, length6 = 12;
// for(i6; i6
rule.date = recurrEventDateAnnual.getDate();
rule.hour = recurrEventTimeAnnual.getHours();
rule.minute = recurrEventTimeAnnual.getMinutes();
return rule;
}
case "monthly": {
console.log("generateRecurringPattern inside monthly");
let rule = new schedule.RecurrenceRule();
rule.date = recurrCycleMonthly;
rule.hour = recurrEventTimeMonthly.getHours();
rule.minute = recurrEventTimeMonthly.getMinutes();
return rule;
}
case "weekly": {
console.log("generateRecurringPattern inside weekly");
let rule = new schedule.RecurrenceRule();
rule.dayOfWeek = weekdayToInt[recurrCycleWeekly];
rule.hour = recurrEventTimeWeekly.getHours();
rule.minute = recurrEventTimeWeekly.getMinutes();
return rule;
}
default: {
return null;
}
}
} catch (err) {
console.error("exception at generateRecurringRule: ", err);
return null;
}
}
function scheduleQueryTask() {
let rule = new Schedule.RecurrenceRule();
rule.minute = [0, 10, 20, 30, 40, 50];
Schedule.scheduleJob(rule, findUserAndQueryAll);
}
module.exports = (url) => {
const rule = new schedule.RecurrenceRule()
rule.second = 0
return schedule.scheduleJob(rule, job(url))
}
function setupSchedule() {
logger.debug('scheduling spider');
var spider_rule = new schedule.RecurrenceRule();
spider_rule.dayOfWeek = 1;
spider_rule.hour = 0;
spider_rule.minute = 0;
schedule.scheduleJob(spider_rule, function() {
package.parsePackages();
});
var spider_rule_packages = new schedule.RecurrenceRule();
spider_rule_packages.dayOfWeek = 1;
spider_rule_packages.hour = 3;
spider_rule_packages.minute = 0;
schedule.scheduleJob(spider_rule_packages, function() {
packageParser.parseAllClickPackages();
});
debug=require("debug")("app"),
express=require("express"),
schedule=require('node-schedule'),
hPromise=require(path.join(constVar.untilPath, "/hPromise.js")),
createMysqlTables=require(path.join(constVar.untilPath, "/createMysqlTables.js")),
app=express(),
clearTempFile=require(path.join(constVar.untilPath,"/clearTempFile")),
aic=require(path.join(constVar.untilPath,"appInitConfig.js")),
initExpress=require("./expressInit.js");
//开启定时任务,定时清理 用户上的传缓存文件
//设置定时job规则,每天凌晨2点清除缓存数据
var timeRule=new schedule.RecurrenceRule();
timeRule.dayOfWeek=[0,new schedule.Range(1,6)];
timeRule.hour=2;
timeRule.minute=0;
schedule.scheduleJob(timeRule, function(result){
clearTempFile(function(){
debug("文件缓存目录已经清除. ",result);
});
});
var hp=new hPromise();
hp.add(function(){
//创建表
createMysqlTables(()=>{
this.next();
});
const schedule = require("node-schedule");
const { UserModel, HigherModel } = require("../models/index");
const { higherController } = require("../controllers");
let rule = new schedule.RecurrenceRule();
rule.minute = [0, 15, 30, 45];
let rule2 = new schedule.RecurrenceRule();
rule2.hour = [3, 15];
rule2.minute = 0;
module.exports = () => {
schedule.scheduleJob(rule, async () => {
await UserModel.update(
{ expired: { $gte: 900 }, level: { $lte: 99 } },
{ $inc: { expired: -900 } }
);
await UserModel.update(
{ expired: { $lt: 900 }, level: { $lte: 99 } },
{ $set: { expired: Number(0), level: Number(1) } }
);