节点调度程序的执行停止了吗?

时间:2018-12-27 11:18:51

标签: google-cloud-firestore scheduled-tasks

如果我不执行db操作,则它适用于所有作业。 但是使用db操作,它永远不会执行。

我已经尝试过了。

jobs json

forEachSeries(
  jobs,
  function(job, cb) {
    let task: any = {};
    const rule = new schedule.RecurrenceRule();

    rule.dayOfWeek = [0, new schedule.Range(1, 6)];

    rule.tz = job.timezone;

    rule.hour = job.hr; // in IST
    rule.minute = job.min; // in IST
    rule.eventType = job.eventType;

    task = schedule.scheduleJob(rule, function() {
      try {
        // not executing below part anyhow, but  when i remove the db operation part , it executing
        console.log("======CAME AFTER TRIGGERED OK ========");

        if (this.rule.eventType[2].type === "REPORT") {
          console.log("======CAME FOR REPORT ========");

          db.collection("employees")
            .where("ID", "==", "E001")
            .get()
            .then(snapshot => {
              db.collection("reports")
                .add({
                  employee_count: snapshot.size,
                  eventType: this.rule.type,
                  created_at: new Date()
                })
                .then(ref => {
                  console.log(" Total Employees docs ======== : ", ref.id);
                })
                .catch(error => {
                  console.log(" =========RSET=============== ", error);
                });
            });
        }
      } catch (e) {
        console.error(e);
      }
    });
    task.rule = rule;
    cb(null);
  },
  function(done) {
    eventList.push(jobs); // done working
  }
);

我正在使用Firestore和Node-Scheduler。

请有人为我自己的代码闪光。

0 个答案:

没有答案