kue
kue copied to clipboard
Update/Search Callback Issue
When saving a new job you are not immediately able to search for it (using search keys) due to the fact that the indexing occurs after the update() functions callback (fn) is invoked. Given the code below the callback is often invoked before the search indexing has completed.
The search indexing should be run before the fn callback is invoked. I am sure it's faster this way though if you have the search enabled I assume you won't mind the penalty of indexing (vs getting incorrect results).
https://github.com/Automattic/kue/blob/master/lib/queue/job.js#L852
this.set('data', json, function() {
// state
this.state(this._state, fn); // I believe this is where the final callback is invoked.
}.bind(this));
// The index logic is happening here though it is a race condition with the above
// code for which will return first. In my experience the code above usually returns first.
if( !exports.disableSearch ) {
if( this.searchKeys() ) {
https://github.com/Automattic/kue/pull/1222