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

Remove Job if not already processed after x seconds #480

Open
bloigge opened this issue Apr 13, 2022 · 2 comments
Open

Remove Job if not already processed after x seconds #480

bloigge opened this issue Apr 13, 2022 · 2 comments

Comments

@bloigge
Copy link

bloigge commented Apr 13, 2022

Is it possible to set some kind of lifespan for a job? If a job never was processed by a worker it should be removed from the queue after x seconds.

I am looking for something like the TTL of RabbitMQ.

Currently I have a function that checks every second if the timestamp of jobs that are waiting are older than x seconds and if the status of each job is "created" - if so the job will get removed from the queue. Is there any other way to do this currently?

setInterval(() => {
  queue.getJobs('waiting', {start: 0, end: 100}).then((jobs) => {
    jobs.forEach((job) => {
      if (job.status === "created") {
        const jobDurationInSeconds = moment.duration(moment().diff(moment(job.options.timestamp))).seconds();
        if (jobDurationInSeconds > 1.5) {
          console.log(`Killing Job: ${job.id}`);
          job.remove();
        } 
      }
    });
  });
}, 1000);
@globalexport
Copy link

Have not tried it myself but you could create a second job running with delayUntil providing it the jobId you would like to remove.

@compwright
Copy link
Collaborator

@bloigge this has not been implemented in bee-queue. Feel free to contribute a PR to add this feature: https://github.com/bee-queue/bee-queue#contributing

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

3 participants