gpt4 book ai didi

javascript - Meteor 和 SyncedCron 任务全天都会触发。时代运转良好

转载 作者:行者123 更新时间:2023-11-28 07:05:09 25 4
gpt4 key购买 nike

这样做的目的是让人们进出我在另一个页面上保存的时间表。我不明白为什么它每天都会为每个人激活。时间对每个人都有效,但有些日子不应该有效。第一段代码是我必须从中提取的模板。第二个是我从中提取并尝试从中创建一个 SyncedCron 。

name: name,
StartTime: startT,
EndTime: endT,
Monday: Monday,
Tuesday: Tuesday,
Wednesday: Wednesday,
Thursday: Thursday,
Friday: Friday,
Saturday: Saturday,
Sunday: Sunday,
queue: false,
status: "Working",
weight: 1,
OOTO: false,
Lunch: false

updateCron: function() {
SyncedCron.stop();
var temp = [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
];

temp.forEach(function(day) {
var temp = {};
// temp[day] = false;

_Techs.find(temp).forEach(function(tech) {


if (tech.startTime != "" && tech[day]) {
var startTimeTemp = "at " + tech.StartTime + " every " + day;
var endTimeTemp = "at " + tech.EndTime + " every " + day;
SyncedCron.add({name: tech.name + " Work Start " + day,
schedule: function(parser) {return parser.text(startTimeTemp);},
job: function() {_Techs.update({_id: tech._id}, {$set: {
queue: true,
totaltickets: 0,
dispatched: false,
timesincelast: new Date(),
status: "Working"
}
});
// console.log(tech.name + " Entered Queue");
return "Worked";
}
});
};

if (tech.endTime != "" && tech[day]) {
var startTimeTemp = "at " + tech.StartTime + " every " + day;
var endTimeTemp = "at " + tech.EndTime + " every " + day;
SyncedCron.add({
name: tech.name + ' Work End Time for ' + day,
schedule: function(parser) {
return parser.text(endTimeTemp);
},
job: function() {
_Techs.update({
_id: tech._id
}, {
$set: {
queue: false,
totaltickets: 0,
dispatched: false,
timesincelast: new Date(),
status: "Working"
}
});
// console.log(tech.name + " Left Queue");
return "Worked";
}
});
};
});
});
SyncedCron.start();
}

最佳答案

看来我发现了问题所在。我使用的是“every”,我应该使用“on”。这就是那一行现在的样子。

var startTimeTemp = "at "+ tech.StartTime + "on "+ day;
以前是这样的

var startTimeTemp = "at "+ tech.StartTime + "every "+ day;

关于javascript - Meteor 和 SyncedCron 任务全天都会触发。时代运转良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31769564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com