Firebase firebase-queue worker 没有收到所有任务任务似乎被丢弃

Firebase firebase-queue worker not receiving all tasks the tasks appear to be dropped

我正在研究这个简单明了的 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

gulp 依赖关系:

"dependencies": {
    "firebase": "2.x",
    "firebase-queue": "x",
    "lodash": "~3.7.0",
    "rsvp": "3.x",
    "node-uuid": "1.4.x",
    "winston": "1.x"
},

此代码片段现在可以使用了。我觉得它是一样的......感觉很困惑。感谢您回复 Frank-

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);
}