The following is standard code, adding tasks to a queue, and then the worker pool will process the tasks. What I am confused about is what it means to have more than 1 worker in the queue, as I don't believe this code will start more than one node.js process?
var Queue = require('firebase-queue');
var firebase = require('firebase');
firebase.initializeApp({
// propriety data
});
var promise = firebase.auth().signInWithEmailAndPassword(process.env.EMAIL, process.env.PASSWORD);
promise.then(function () {
return createQueue();
}, function (error) {
console.error(error);
});
var queue;
function createQueue() {
var db = firebase.database();
var ref = db.ref('quote-request-queue');
var tasks = db.ref('quote-request-queue/tasks');
tasks.push({'foo': 'bar'});
tasks.push({'foo': 'bar'});
tasks.push({'foo': 'bar'});
const opts = {
};
queue = new Queue(ref, opts, function (data, progress, resolve, reject) {
// Read and process task data
console.log(data);
// Do some work
progress(50);
// Finish the task asynchronously
setTimeout(function () {
resolve();
}, 100);
});
console.log('worker count:', queue.getWorkerCount());
}
my question is - is it necessary to call resolve() before the next item in the queue will be processed by another worker?
I want to find out how to make workers block each other (for the purposes of DB atomicity) as well as to have workers work in parallel on separate tasks. (They will work in parallel/concurrently if there is I/O happening in the processing function).
How can I control blocking/non-blocking worker queues with Firebase?