Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing completed jobs based on age not working as expected #1353

Closed
benja8151 opened this issue Aug 8, 2022 · 1 comment
Closed

Removing completed jobs based on age not working as expected #1353

benja8151 opened this issue Aug 8, 2022 · 1 comment

Comments

@benja8151
Copy link

According to documentation, removeOnComplete job option allows us to configure maximum age for a job to be kept after completion, in seconds. However, the check for expired completed jobs appears to only be done after another job is processed.

Expected Behavior

Setting age property on removeOnComplete should limit how many seconds a job is kept after being completed. Job should be automatically removed after specified time.

Current Behavior

Job is removed based on age only after another job in the same queue is processed, which could lead to cases where jobs could be kept for indefinite time, if no new jobs are added to the queue. This behaviour is different if you set removeOnComplete: true or removeOnComplete: {count: 0} - here, job is immediately and correctly deleted at completion.

Steps to Reproduce

  1. Create a Queue and QueueScheduler with defaultJobOptions:
const queue = new Queue("queue", {
  defaultJobOptions: {
    removeOnComplete: {age: 5},
  }
);
const queueScheduler = new QueueScheduler("queue");
  1. Create a Worker:
const worker = new Worker("queue",
  async (job) => {console.log(`Job ${job.name}#${job.id} is processed.`);}
);
worker.on("completed", (job) => console.log(`Completed job ${job.name}#${job.id} with data ${job.data}`));
  1. Add job to queue:
queue.add("job", { random: "data" });
  1. Checking situation in redis shows us that job is not automatically removed.
@benja8151 benja8151 changed the title Removing completed jobs based on age not working properly Removing completed jobs based on age not working as expected Aug 8, 2022
@manast manast added the enhancement New feature or request label Aug 9, 2022
@manast
Copy link
Contributor

manast commented Aug 9, 2022

The feature is working as designed.
This may not be the desirable behaviour in some situations, but for most cases, when you have a healthy queue processing jobs regularly it should not be a big issue.

@manast manast closed this as completed Aug 9, 2022
@manast manast added works as designed and removed enhancement New feature or request labels Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants