quirrel-dev / quirrel

The Task Queueing Solution for Serverless.
https://quirrel.dev
MIT License
892 stars 67 forks source link

Job with a delay set gets executed immediately #27

Closed maxfi closed 3 years ago

maxfi commented 3 years ago

Setting a delay doesn't actually delay the execution of the job. I've only tested this in development mode so not sure if it's also a problem in the hosted version? With the following enqueue the job gets executed immediately:

import reminderQueue from "./queues/reminder";

// pages/api/setupReminder.js
export default async (req, res) => {
  const email = req.body;
  await reminderQueue.enqueue(email, {
    id: email,
    delay: "1m",
    repeat: {
      every: "1m",
      times: 1,
    },
  });
  res.status(200).end();
};

Full repro here: https://github.com/maxfi/quirrel-dev-water-reminder-demo

Skn0tt commented 3 years ago

Hmm, that doesn't seem right. Thanks for providing a repro, will look into it.

Skn0tt commented 3 years ago

Found the offender: https://github.com/quirrel-dev/quirrel/blob/b72891d98b819d200151d7df33e5778411045daf/api/src/scheduler/jobs-repo.ts#L150

I guess this should have been caught by one of the functional tests, but apparently not this specific combination of delay and repeat.every ...

Will provide a PR immediately.

maxfi commented 3 years ago

Awesome. Thanks @Skn0tt. 🙏

Skn0tt commented 3 years ago

Fixed in v0.10.1.