1
我正在通過這個直截了當的firebase隊列示例工作。 我讓工作人員接收任務並完成任務,但由於某些原因,任務正在丟失。Firebase firebase隊列工作人員沒有收到所有任務似乎要丟棄的任務
我推20個任務,總是處理少於20個。我想象這是我的代碼有問題。熟悉firebase/firebase-queue的人可以參考一下嗎?
我正在運行node.js.
var Queue = require('firebase-queue'),
Firebase = require('firebase');
var ref = new Firebase(FIREBASE_URL);
// oauth custom token. (create a custom token from dashboard)
// TODO add a catch.
ref.authWithCustomToken(BIG_SECRET, function(err, authData){
if (err) {
console.log("Login failed with error: ", error);
} else {
console.log("Authenticated successfully with payload: ", authData);
}
});
var options = {
specId: 'task_1',
numWorkers: 1
};
// need to learn more about specs...
ref.child('queue').child('specs').set({
task_1: {
in_progress_state: 'task_1_in_progress',
//finished_state: 'spec_1_finished', // this appears to be used for a pipeline of tasks!
timeout: 100000 // timeout for the queued item...
}
});
var numCalled = 0;
/*
* @param data The json object representing the task.
* @param progress A function we can call to declare progress so far.
* @param resolve A function to call when the task is completed.
* @param reject A function to call if the data isn't good. (not sure how this ties in bigger scheme)
*/
var queue = new Queue(ref.child('queue'), options, function(data, progress, resolve, reject) {
numCalled++
console.log('queue is doing something' + numCalled);
console.log(data);
// the injected progress is a way to indicate amount of task completed.
progress(50);
// Finish the task asynchronously
// setTimeout(function() {
resolve();
// }, 1000);
});
// going to exercise the queue I think.. LOL
var ref = new Firebase("https://torrid-heat-1819.firebaseio.com/queue/tasks");
// setting the state seems like a bad idea.
//ref.push({"a": "b","_state": "task_1_in_progress"});
//ref.push({"c": "d","_state": "task_1_in_progress"});
//ref.push({"e": "f","_state": "task_1_in_progress"});
//make 20 requests..
for (i = 0; i < 20; i++) {
// this seems to delay execution...
//setTimeout(function() {
ref.push({"count": i});
// }, 10);
}
這裏是輸出 -
queue is doing something1
{ count: 0 }
queue is doing something2
{ count: 2 }
queue is doing something3
{ count: 3 }
queue is doing something4
{ count: 4 }
queue is doing something5
{ count: 6 }
queue is doing something6
{ count: 7 }
queue is doing something7
{ count: 8 }
queue is doing something8
{ count: 9 }
queue is doing something9
{ count: 10 }
queue is doing something10
{ count: 12 }
queue is doing something11
{ count: 13 }
queue is doing something12
{ count: 14 }
queue is doing something13
{ count: 15 }
queue is doing something14
{ count: 16 }
queue is doing something15
{ count: 17 }
queue is doing something16
{ count: 19 }
節點版本:v0.12.7
一飲而盡依賴性:
"dependencies": {
"firebase": "2.x",
"firebase-queue": "x",
"lodash": "~3.7.0",
"rsvp": "3.x",
"node-uuid": "1.4.x",
"winston": "1.x"
},
您正在運行哪個節點版本的節點? –
Frank,版本是v0.12.7。我添加了gulp依賴關係。由於代碼非常簡單,我覺得我必須在某處犯錯誤。 –