Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ The reserved keys are:
- `_owner` - A unique ID for the worker and task number combination to ensure only one worker is responsible for the task at any time.
- `_progress` - A number between 0 and 100, reset at the start of each task to 0.
- `_error_details` - An object containing the error details from a previous task execution. If present, it may contain a `previous_state` string (or `null` if there was no previous state, in the case of malformed input) capturing the state the task was in when it errored, an `error` string from the `reject()` callback of the previous task, and an `attempts` field containing the number of retries attempted before failing a task. If the `suppressStack` queue option is not set to `true`, there may also be a `error_stack` field containg a stack dump of any error passed into the `reject()` function.
- `_id` - The Firebase key of the task.

By default the data is sanitized of these keys, but you can disable this behavior by setting `'sanitize': false` in the [queue options](#queue-worker-options-optional).

Expand Down Expand Up @@ -229,6 +230,9 @@ These don't have to use a custom token, for instance you could use `auth != null
".validate": false
}
},
"_id": {
".validate": "newData.isString()"
},
"property_1": {
".validate": "/* Insert custom data validation code here */"
},
Expand Down Expand Up @@ -434,6 +438,7 @@ root
- _progress: 0
- _state: "sanitize_message_in_progress"
- _state_changed: 1431475215737
- _id: $taskId
- message: "Hello Firebase Queue Users!"
- name: "Chris"
```
Expand All @@ -451,6 +456,7 @@ root
- _progress: 100
- _state: "sanitize_message_finished"
- _state_changed: 1431475215918
- _id: $taskId
- message: "Hello Firebase ***** Users!"
- name: "Chris"
```
Expand Down
4 changes: 3 additions & 1 deletion src/lib/queue_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ QueueWorker.prototype._tryToProcess = function(nextTaskRef, deferred) {
}
};
}
task._id = nextTaskRef.key();
if (_.isUndefined(task._state)) {
task._state = null;
}
Expand Down Expand Up @@ -498,7 +499,8 @@ QueueWorker.prototype._tryToProcess = function(nextTaskRef, deferred) {
'_state_changed',
'_owner',
'_progress',
'_error_details'
'_error_details',
'_id'
].forEach(function(reserved) {
if (snapshot.hasChild(reserved)) {
delete data[reserved];
Expand Down
4 changes: 2 additions & 2 deletions test/lib/queue_worker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ describe('QueueWorker', function() {
try {
testRef.off();
var task = snapshot.val();
expect(task).to.have.all.keys(['_state', '_progress', '_state_changed', '_error_details']);
expect(task).to.have.all.keys(['_state', '_progress', '_state_changed', '_error_details', '_id']);
expect(task['_state']).to.equal('error');
expect(task['_state_changed']).to.be.closeTo(new Date().getTime() + th.offset, 250);
expect(task['_progress']).to.equal(0);
Expand Down Expand Up @@ -1314,7 +1314,7 @@ describe('QueueWorker', function() {
it('should not sanitize data passed to the processing function when specified', function(done) {
qw = new th.QueueWorker(tasksRef, '0', false, false, function(data, progress, resolve, reject) {
try {
expect(data).to.have.all.keys(['foo', '_owner', '_progress', '_state', '_state_changed']);
expect(data).to.have.all.keys(['foo', '_owner', '_progress', '_state', '_state_changed', '_id']);
done();
} catch (error) {
done(error);
Expand Down