-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
39 lines (34 loc) · 970 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const Queue = require('rethinkdb-job-queue')
const rethinkdbdash = require('rethinkdbdash')
module.exports = function (options = {}) {
let { queues, connection = {} } = options
connection.db = connection.db || 'JobQueue'
const r = rethinkdbdash(connection)
let queuesPromise = queues ? Promise.resolve(queues) : r.tableList()
queuesPromise = queuesPromise.then(queues => {
return queues.map(q => {
if (q instanceof Queue) {
return q
}
return new Queue(r, {
name: q
})
})
})
return {
async queues () {
const queues = await queuesPromise
return Promise.all(queues.map(queue => {
return queue.summary().then(summary => {
summary.name = queue.name
return summary
})
}))
},
async queue (name) {
const queues = await queuesPromise
const queue = queues.find(({_name}) => _name === name)
return queue.r.table(name)
}
}
}