首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防火墙-队列工作人员没有接收到所有任务,任务似乎被删除。

防火墙-队列工作人员没有接收到所有任务,任务似乎被删除。
EN

Stack Overflow用户
提问于 2015-09-14 00:49:35
回答 1查看 619关注 0票数 1

我正在研究这个直接的防火墙队列示例。我让员工接收并完成任务,但由于某些原因,任务正在被删除。

我推了20个任务,处理的总是少于20个。我想这是我的代码中的一个问题。熟悉防火墙/防火墙队列的人能看一看吗?

我正在运行node.js。

代码语言:javascript
复制
  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);
  }

这是输出-

代码语言:javascript
复制
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

吞咽依赖:

代码语言:javascript
复制
"dependencies": {
    "firebase": "2.x",
    "firebase-queue": "x",
    "lodash": "~3.7.0",
    "rsvp": "3.x",
    "node-uuid": "1.4.x",
    "winston": "1.x"
},
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-15 02:43:29

这个代码片段现在起作用了。我觉得这是一样的.感觉很困惑。谢谢你回复弗兰克-

代码语言:javascript
复制
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);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32555978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档