我是否使用 node-schedule 包将任务安排了 6 个月?

问题描述

下面是我的代码。这里 arr 是一组上传文件路径,我想取消链接意味着在 6 个月后删除它们。我的代码是对的吗?因为我只能在 6 个月后检查结果我不知道如何测试。我正在通过客户端的 AJAX 调用调用此端点。

      router.get("/scheduleTask",function (req,res,next) {
    
              var y,m,d,h,mi;
              var da = new Date();
              
                y = da.getFullYear();
                da.setMonth(da.getMonth() + 5);
                m = da.getMonth();
                d = da.getDate();
                h = da.getHours();
                mi = da.getMinutes();

                var date = new Date(y,mi,0);

                var j = schedule.scheduleJob(date,function () {
                  //first scheduler start
                  arr.Bigpaths4Clients.forEach((element2) => {
                    fs.unlink(element2.path,function (err,success) {
                      if (err) {
                        console.log(err);
                        return res.end(
                          '{"msg" : "Unable to unlink the arr files : Rejected","status" : 700}'
                        );
                      } else {
                    console.log("Delete files after 6 months");
                 }
    })
    })

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)