Firebase firebase-queue worker未接收到任务似乎被删除的所有任务

时间:2015-09-14 00:49:36

标签: firebase firebase-realtime-database

我正在研究这个直接的firebase-queue示例。 我让工人接收任务并完成它们,但由于某些原因,任务正在被删除。

我推送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"
},

1 个答案:

答案 0 :(得分:0)

此代码段现在可以使用了。我觉得它是一样的但是......感到困惑。谢谢你回复弗兰克 -

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