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

feature request to optionally only allow unique items in queue #79

Open
danday74 opened this issue Jan 19, 2022 · 2 comments
Open

feature request to optionally only allow unique items in queue #79

danday74 opened this issue Jan 19, 2022 · 2 comments

Comments

@danday74
Copy link

danday74 commented Jan 19, 2022

This library is almost perfect for my needs.

Currently queue works like so:

q.push(function (cb) {
  const result = 'two'
  cb(null, result)
})

I would like it to support queuing only unique items like so:

var q = queue({ results: [], unique: true })

The API would then work as follows;

// item added to queue as normal (still works)
q.push(function (cb) {
  const result = 'two'
  cb(null, result)
})
// item added to queue with an id - if unique is true then the id must be unique or else the job is ignored
const id = 'my-id'
q.push(id, function (cb) {
  const result = 'two'
  cb(null, result)
})

// job ignored coz same id used
q.push(id, function (cb) {
  const result = 'two'
  cb(null, result)
})

Please consider this request - thanks

Note that this request would benefit the developer, allowing the library to support:

q.getJobsWaiting() // array of ids that refer to jobs waiting to be processed, order by time job added
q.getJobsProcessing() // array of ids that refer to jobs currently running, order by time job added
q.getJobsComplete() // array of ids that refer to completed jobs that were resolved, order by time job added
q.getJobsFailed() // array of ids that refer to completed jobs that were rejected, order by time job added

If IDs were not given then these methods would simply return empty arrays.

@onichandame
Copy link

my 2 cents. For better backwards compatibility, the signature of push(fn) function should remain unchanged. To pass named task(job with id) to the queue, we could allow the following:

import { Task }, queue from 'queue'

class MyTask extends Task {
  public async run() {
    // job implementation here...
  }
}

const q = queue()

q.push(MyTask) // effective, queue size 1
q.push(MyTask) // not effective, queue size still 1

@danday74
Copy link
Author

danday74 commented Dec 9, 2022

9 months later, having exactly the same problem again. When I log a job I get:

JOB DONE () => this.preloadIframe(i)
RESULT = undefined

this.q.on('success', function (result, job) { console.log('JOB DONE', job.toString()) console.log('RESULT =', result) })

output as expected. However, the same func is being used for all jobs, just passing in a different value for i

from the logs it is impossible to distinguish which job is which. Allowing a job ID would solve this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants