2016-06-01 16:39:01 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var util = require('util');
|
2019-10-04 00:24:39 +08:00
|
|
|
var QueryBase = require('./query-base');
|
2016-06-01 16:39:01 +08:00
|
|
|
var Query = require('./query');
|
|
|
|
var Fallback = require('./fallback');
|
2019-10-04 00:24:39 +08:00
|
|
|
var jobStatus = require('../../job-status');
|
2016-06-01 16:39:01 +08:00
|
|
|
|
2019-12-24 01:19:08 +08:00
|
|
|
function QueryFallback (job, index) {
|
2016-06-01 16:39:01 +08:00
|
|
|
QueryBase.call(this, index);
|
|
|
|
|
|
|
|
this.init(job, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(QueryFallback, QueryBase);
|
|
|
|
|
|
|
|
QueryFallback.is = function (query) {
|
|
|
|
if (Query.is(query)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
QueryFallback.prototype.init = function (job, index) {
|
|
|
|
this.query = new Query(index);
|
|
|
|
|
|
|
|
if (Fallback.is(job.query.query[index])) {
|
|
|
|
this.fallback = new Fallback(index);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
QueryFallback.prototype.getNextQuery = function (job) {
|
|
|
|
if (this.query.hasNextQuery(job)) {
|
|
|
|
return this.query.getNextQuery(job);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.fallback && this.fallback.hasNextQuery(job)) {
|
|
|
|
return this.fallback.getNextQuery(job);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
QueryFallback.prototype.setStatus = function (status, job, previous, errorMesssage) {
|
|
|
|
var isValid = false;
|
|
|
|
var appliedToFallback = false;
|
|
|
|
|
|
|
|
if (previous.isValid && !previous.appliedToFallback) {
|
|
|
|
if (status === jobStatus.FAILED || status === jobStatus.CANCELLED) {
|
|
|
|
this.query.setStatus(jobStatus.SKIPPED, job, errorMesssage);
|
|
|
|
|
|
|
|
if (this.fallback) {
|
|
|
|
this.fallback.setStatus(jobStatus.SKIPPED, job);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!previous.isValid) {
|
|
|
|
isValid = this.query.setStatus(status, job, errorMesssage);
|
|
|
|
|
|
|
|
if (this.fallback) {
|
|
|
|
if (!isValid) {
|
|
|
|
isValid = this.fallback.setStatus(status, job, errorMesssage);
|
|
|
|
appliedToFallback = true;
|
|
|
|
} else if (isValid && this.isFinalStatus(status) && !this.fallback.hasNextQuery(job)) {
|
|
|
|
this.fallback.setStatus(jobStatus.SKIPPED, job);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { isValid: isValid, appliedToFallback: appliedToFallback };
|
|
|
|
};
|
|
|
|
|
2016-06-03 00:02:25 +08:00
|
|
|
QueryFallback.prototype.getStatus = function (job) {
|
|
|
|
return this.query.getStatus(job);
|
|
|
|
};
|
|
|
|
|
2016-06-01 16:39:01 +08:00
|
|
|
module.exports = QueryFallback;
|