【问题标题】:setInterval() is not wotking in azure microsoftsetInterval() 在 azure microsoft 中不起作用
【发布时间】: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


【解决方案1】:

这里缺少代码,初始条件中的括号和 setInterval 函数调用的右括号

【讨论】:

  • 是的,我知道我忘记复制所有代码,但它不能在 azure 中工作,它在没有 azure 的情况下也能工作
猜你喜欢
  • 2017-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-19
  • 2016-01-21
  • 1970-01-01
  • 2011-11-07
  • 2018-05-08
相关资源
最近更新 更多