Refactored job fallback initialization
This commit is contained in:
parent
cd439757b7
commit
86d02ab0b7
@ -67,28 +67,36 @@ JobFallback.is = function (query) {
|
||||
};
|
||||
|
||||
JobFallback.prototype.init = function () {
|
||||
// jshint maxcomplexity: 9
|
||||
for (var i = 0; i < this.data.query.query.length; i++) {
|
||||
if ((this.data.query.query[i].onsuccess || this.data.query.query[i].onerror) &&
|
||||
!this.data.query.query[i].status) {
|
||||
if (shouldInitStatus(this.data.query.query[i])){
|
||||
this.data.query.query[i].status = jobStatus.PENDING;
|
||||
}
|
||||
if (shouldInitQueryFallbackStatus(this.data.query.query[i])) {
|
||||
this.data.query.query[i].fallback_status = jobStatus.PENDING;
|
||||
} else if (!this.data.query.query[i].status){
|
||||
this.data.query.query[i].status = jobStatus.PENDING;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.data.status) {
|
||||
this.data.status = jobStatus.PENDING;
|
||||
if (this.data.query.onsuccess || this.data.query.onerror) {
|
||||
if (shouldInitStatus(this.data)) {
|
||||
this.data.status = jobStatus.PENDING;
|
||||
}
|
||||
|
||||
if (shouldInitFallbackStatus(this.data)) {
|
||||
this.data.fallback_status = jobStatus.PENDING;
|
||||
}
|
||||
} else if (!this.data.status) {
|
||||
this.data.status = jobStatus.PENDING;
|
||||
}
|
||||
};
|
||||
|
||||
function shouldInitStatus(jobOrQuery) {
|
||||
return !jobOrQuery.status;
|
||||
}
|
||||
|
||||
function shouldInitQueryFallbackStatus(query) {
|
||||
return (query.onsuccess || query.onerror) && !query.fallback_status;
|
||||
}
|
||||
|
||||
function shouldInitFallbackStatus(job) {
|
||||
return (job.query.onsuccess || job.query.onerror) && !job.fallback_status;
|
||||
}
|
||||
|
||||
JobFallback.prototype.getNextQueryFromQueries = function () {
|
||||
for (var i = 0; i < this.queries.length; i++) {
|
||||
if (this.queries[i].hasNextQuery(this.data)) {
|
||||
|
Loading…
Reference in New Issue
Block a user