Socket
Socket
Sign inDemoInstall

better-queue

Package Overview
Dependencies
128
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.6 to 3.3.0

14

lib/queue.js

@@ -200,2 +200,13 @@ var uuid = require('node-uuid');

Queue.prototype.cancel = function (taskId, cb) {
cb = cb || function(){};
var self = this;
var worker = self._workers[taskId];
if (worker) {
worker.cancel();
}
console.log("CANCEL")
self._store.deleteTask(taskId, cb);
}
Queue.prototype.push = function (input, cb) {

@@ -275,6 +286,7 @@ var self = this;

var writeId = self._writing[taskId].id;
var tickets = self._writing[taskId].tickets;
self._store.putTask(taskId, task, priority, function (err) {
// Check if task has changed since put
var tickets = self._writing[taskId].tickets;
if (self._writing[taskId].id !== writeId) {

@@ -281,0 +293,0 @@ self._writeQueue.unshift(taskId);

@@ -28,2 +28,12 @@

MemoryStore.prototype.deleteTask = function (taskId, cb) {
var self = this;
delete self._tasks[taskId];
delete self._priorities[taskId];
if (self._queue.indexOf(taskId) > -1) {
self._queue.splice(self._queue.indexOf(taskId), 1);
}
cb();
}
MemoryStore.prototype.putTask = function (taskId, task, priority, cb) {

@@ -30,0 +40,0 @@ var self = this;

@@ -59,2 +59,6 @@ var uuid = require('node-uuid');

SQLiteStore.prototype.deleteTask = function (taskId, cb) {
this.db.run("DELETE FROM tasks WHERE id = ?", [taskId], cb);
}
SQLiteStore.prototype.putTask = function (taskId, task, priority, cb) {

@@ -61,0 +65,0 @@ try {

2

package.json
{
"name": "better-queue",
"version": "3.2.6",
"version": "3.3.0",
"description": "Better Queue for NodeJS",

@@ -5,0 +5,0 @@ "main": "lib/queue.js",

@@ -431,2 +431,8 @@ # Better Queue - Powerful flow control

You can also call `.cancel(taskId)` to cancel and unqueue the task.
```js
uploader.cancel('/path/to/file.pdf');
```
Note that if you enable this option in batch mode, it will cancel the entire batch!

@@ -433,0 +439,0 @@

@@ -106,2 +106,17 @@ var Queue = require('./lib/queue')

// var q = new Queue(function (b, cb) {
// console.log("starting");
// setTimeout(function () {
// console.log('done')
// cb()
// }, 95)
// }, { maxTimeout: 100 })
// q.on('task_failed', function (err) {
// console.log('timeout', err)
// })
// q.on('task_finish', function (res) {
// console.log('finished!', res)
// })
// q.push(1)
// var q = new Queue(function (b, cb) {
// console.log("Pushed %s.", b);

@@ -108,0 +123,0 @@ // cb();

@@ -288,2 +288,47 @@ var assert = require('assert');

it('should timeout and fail', function (done) {
var tries = 0;
var q = new Queue(function (n, cb) {
tries++;
setTimeout(function () {
cb(null, 'done!')
}, 3)
}, { maxTimeout: 1, maxRetries: 2 })
q.push(1)
.on('finish', function (result) {
assert.ok(false)
})
.on('failed', function (err) {
assert.equal(tries, 2);
setTimeout(function () {
done();
}, 5)
})
})
it('should cancel while running and in queue', function (done) {
var q = new Queue(function (task, cb) {
assert.ok(task.n, 2)
setTimeout(function () {
q.cancel(1);
}, 1)
return {
cancel: function () {
done();
}
}
}, {
id: 'id',
merge: function (a,b) {
assert.ok(false);
}
})
q.push({ id: 1, n: 1 })
.on('queued', function () {
q.cancel(1, function () {
q.push({ id: 1, n: 2 });
})
});
})
})

@@ -201,3 +201,6 @@ var assert = require('assert');

var finished = 0;
var q = new Queue(function (n, cb) { cb(null, n) }, {
var q = new Queue(function (n, cb) {
cb(null, n)
}, {
batchDelay: 3,
id: function (n, cb) {

@@ -212,2 +215,4 @@ cb(null, n % 2 === 0 ? 'even' : 'odd');

var queued = 0;
q.on('task_queued', function (taskId, r) {
})
q.on('task_finish', function (taskId, r) {

@@ -225,9 +230,2 @@ finished++;

})
q.on('task_queued', function (taskId, r) {
queued++;
if (queued >= 2) {
q.resume();
}
})
q.pause();
q.push(1);

@@ -234,0 +232,0 @@ q.push(2);

@@ -17,3 +17,2 @@ var assert = require('assert');

completed++;
assert.ok(stat.elapsed > 0)
elapsedTotals += stat.elapsed;

@@ -20,0 +19,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc