Skip to content

Remove Job if not already processed after x seconds #480

@bloigge

Description

@bloigge

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);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions