2

I have a Firebase queue and two specs, on the same queue and from the client I am making a push on the queue with the start state as only read_write_start, either both my specs gets executed by default or the wrong spec gets executed i.e. the "read_start" spec gets executed

Client Side :

var readWriteTokenData = {};
                        readWriteTokenData ["_start"] = "read_write_start";
$firebaseArray(QueueRef.child('tasks')).$add(readWriteTokenData);

SERVER SIDE :

var queueRef = new Firebase('https://<INSTANCE>.firebaseio.com/queue');

    var specs: {
        "read_write_token": {
            "_start_state" : "read_write_start",
            "in_progress_state": "read_write_in_progress",
            "finished_state": "read_write_finished",
            "error_state": "read_write_error"
        },
        "read_token": {
            "_start_state" : "read_start",
            "in_progress_state": "read_in_progress",
            "finished_state": "read_finished",
            "error_state": "read_error"
        }
     }

    queueRef.child('specs').update(specs);

    var option1 = {
        'specId' : 'read_token',
        'numWorkers': 1
    };

    var option2 = {
        'specId' : 'read_write_token',
        'numWorkers': 1
    };

var ReadQueue = new Queue(queueRef,option1,function(data, progress, resolve, reject) {

    data.readToken = 'PQR';

    if(readToken){
        resolve(data);
    } else {
        reject(data);
    }
});

var ReadWriteQueue = new Queue(queueRef,option2,function(data, progress, resolve, reject) {

    data.readWriteToken = 'ABC';
    if(readWriteToken){
        resolve(data);
    } else {
        reject(data);
    }
});

I am not sure what am i missing here the documentation is not clear

Do I have to instantiate a new Queue Reference for each spec? Is spec only for chaining jobs ?

Should i do this

var queueRef1 = new Firebase('https://<INSTANCE>.firebaseio.com/read/queue');
var queueRef2 = new Firebase('https://<INSTANCE>.firebaseio.com/readwrite/queue');
TJ_
  • 255
  • 3
  • 12
  • looks like you are using `option2` on both queue workers. – Ron Harlev Mar 24 '16 at 22:21
  • That is a mistake in the above code not in my actual code though – TJ_ Mar 25 '16 at 00:35
  • The spec needs to be `start_state` and not `_start_state` - the workers are both probably picking up tasks with a `_state` of `null` and competing with each other – Chris Raynor Mar 25 '16 at 21:27
  • @ChrisRaynor What is the better option from this for different types of tasks: 1) putting all tasks in a single queue with different specs (not chained) and pushing from client apps with _state set ,or 2) creating multiple queues with multiple data to perform different types of tasks like new_user_added, user_removed, etc etc.. ?? – kirtan403 Nov 13 '16 at 06:08
  • Depends on how complicated you want your setup to be, but in general splitting queues into different locations means less contention on retrieving tasks, but it means you can't chain specs – Chris Raynor Nov 18 '16 at 00:39

0 Answers0