【发布时间】:2021-02-02 11:13:15
【问题描述】:
setInterval() 在 Azure Microsoft 中不起作用。我需要一个函数来每月或每周完成任务吗?那我该怎么办?代码在没有 azure 的情况下工作,但在 azure 不工作?
nodejs 代码:
setInterval(async function check() {
if ((date.getDate() == 8) && (date.getHours() == 18) && (date.getMinutes() == 39) && (date.getSeconds() == 00)) {
await Drawings.find({}).then((data) => {
data.sort(function (a, b) {
return b.stars - a.stars;
})
if (data == null) {
return;
}
AllDrawings.updateMany({
"potmCurrentWinner": true
}, {
$set: {
"potmCurrentWinner": false
}
}, async function (err) {
if (err) {
return;
}
// move the drawing to potm
await AllDrawings.updateOne({
"DrawingName": data[0]['DrawingName']
}, {
$set: {
"potmCurrentWinner": true,
"potm": true
}
}, async function (err) {
//move file
await User.updateOne({
userName: data[0].Drawer
}, {
$inc: {
stars: 25
}
})
console.log("done3");
await User.updateOne({
userName: data[0].Drawer
}, {
$inc: {
drawingOfTheMonth: 1
}
});
//delete all drawwing the u give star
await User.updateMany({}, {
$set: {
drawingThatGotYourStar: []
}
});
await Drawings.deleteMany({});
console.log("done4");
});
});
})
【问题讨论】:
-
老兄,这太疯狂了,你每 1 毫秒运行一次。想想更好的方法。比如,setTimeout 到 setTimout 获取当前日期并检查您希望它下次运行的时间。
-
它也没有用
-
尝试使用 cronjob
-
@AhmedKhalid “不在 Azure 中工作”是什么意思?您是如何部署代码的?
标签: node.js azure azure-functions google-api-nodejs-client