Comparing version 1.0.1 to 1.1.0
CHANGELOG | ||
========= | ||
* 1.1.0 Add find(), count() and distinct(). | ||
* 1.0.1 Ignore `undefined` output | ||
* 1.0.0 Initial releast |
{ | ||
"name": "combee", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Shell for bee-queue", | ||
@@ -25,2 +25,3 @@ "main": "repl.js", | ||
"bee-queue": "^1.2.2", | ||
"get-value": "^3.0.1", | ||
"redis": "^2.8.0", | ||
@@ -27,0 +28,0 @@ "sift": "^8.5.0", |
@@ -66,3 +66,7 @@ combee | ||
combee::> | ||
combee::> combee.foo.find('waiting', {'data.yolo': 'yolo'}) | ||
combee::> combee.foo.count('waiting', {'data.yolo': 'yolo'}) | ||
combee::> combee.foo.distinct('waiting', 'data.yolo', {}) | ||
``` |
71
repl.js
@@ -9,2 +9,3 @@ #!/usr/bin/env node | ||
const sift = require('sift').default; | ||
const getValue = require('get-value'); | ||
@@ -184,2 +185,72 @@ | ||
} | ||
/** | ||
* Utility function for finding jobs that match the given criteria | ||
* (the job type and filter). | ||
* | ||
* @param {string} jobType The type of job to search. | ||
* @param {Object} filter A sift-compatible filter. | ||
*/ | ||
async find(jobType, filter) { | ||
const matches = this._find(jobType, filter); | ||
console.log(matches); | ||
repl.repl.prompt(); | ||
} | ||
count(jobType, filter) { | ||
this.countAsync(jobType, filter); | ||
} | ||
async countAsync(jobType, filter) { | ||
const matches = await this._find(jobType, filter); | ||
console.log(`found ${matches.length} jobs`); | ||
repl.repl.prompt(); | ||
} | ||
distinct(jobType, field, filter) { | ||
this.distinctAsync(jobType, field, filter); | ||
} | ||
async distinctAsync(jobType, field, filter) { | ||
const matches = await this._find(jobType, filter); | ||
const vals = new Map(); | ||
for (const match of matches) { | ||
const val = getValue(match, field); | ||
vals.set(val, (vals.get(val) || 0) + 1) | ||
} | ||
console.log(); // purge to next line for readability | ||
for (const [ key, count ] of vals) { | ||
console.log(`${key}: ${count}`); | ||
} | ||
repl.repl.prompt(); | ||
} | ||
async _find(jobType, filter) { | ||
const BATCH_SIZE = 50; | ||
const jobStats = await this.queue.checkHealth(); | ||
const count = jobStats[jobType]; | ||
const sifted = sift(filter); | ||
let matches = []; | ||
for (let i=0; i < count; i+=BATCH_SIZE) { | ||
const jobs = await this.queue.getJobs(jobType, { | ||
size: BATCH_SIZE, | ||
start: i, | ||
}); | ||
const matched = jobs.filter(sifted); | ||
if (matched && matched.length) { | ||
matches = matches.concat(matched); | ||
} | ||
} | ||
return matches.map(this.stripDownJob); | ||
} | ||
} | ||
@@ -186,0 +257,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9835
228
71
5
+ Addedget-value@^3.0.1
+ Addedget-value@3.0.1(transitive)
+ Addedisobject@3.0.1(transitive)