veliovgroup / mail-time

📮 Email queue extending NodeMailer with multi SMTP transports and horizontally scaled applications support

Home Page:https://www.npmjs.com/package/mail-time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

why find sendAt: {$lt: new Date(Date.now() - (this.interval * 4))} in __send? it's impossible.

fangjj opened this issue · comments

commented

I have a question:

  1. why find sendAt: {$lt: new Date(Date.now() - (this.interval * 4))} in __send? it's impossible.
___send(ready) {
    this.collection.findOneAndUpdate({
      $or: [{
        isSent: false,
        sendAt: {
          $lte: new Date()
        },
        tries: {
          $lt: this.maxTries
        }
      }, {
        isSent: true,
        sendAt: {
          $lt: new Date(Date.now() - (this.interval * 4))
        },
        tries: {
          $lt: this.maxTries
        }
      }]
    }, {
      $set: {
        isSent: true,
        sendAt: new Date(Date.now() + this.interval)
      },
      $inc: {
        tries: 1
      }
    }

4 is this.failsToNext?

@fangjj

We expect to have no records in database, if record exists it means email wasn't sent or server encountered an error.

  1. this.interval * 4 — used to reduce selection, also we give this task (this.interval * 4) time to finish, if email wasn't send during that time-frame we assume it's zombie-task
  2. isSent: true — Means we started sending email, but as long as we're having this recored in DB it isn't actually sent (again, zombie-task)
  3. $lt: this.maxTries — We won't recover zombie-tasks indefinitely

Home that helps, let me know wdyt :)

Closed due to silence at issue owner end.
Feel free to reopen it in case if the issue still persists on your end.