我的前端将发送该搜索对象,“ {{deckStatus:” Vacant“,awayStatus:null}或{deckStatus:null,awayStatus:null}等。
我想制作一个健壮的过滤器,该过滤器将根据状态和状态(基于发送的内容)在卡座数组上过滤(仅选择状态为“已占用”或“状态为空”是空置的对象,这是我的文档。)< / p>
// continuing the previous promise chain:
.then((queueId) => convertQueueIdToBuildId(jenkins, jobName, queueId, 5000))
.then((buildId) => waitForJobToFinish(jenkins, jobName, buildId, 5000))
.catch(printErrorAndExit);
function convertQueueIdToBuildId(jenkins, jobName, queueId, interval, spinner) {
return convertQueueIdToBuildIdInner(queueId)
.then((data) => {
if (isNumber(data)) {
return data;
}
return waitFor(interval)
.then(() => convertQueueIdToBuildId(jenkins, jobName, queueId, interval, spinner));
});
function convertQueueIdToBuildIdInner(queueId) {
return new Promise((resolve, reject) => {
jenkins.queue.item(queueId, (err, data) => {
if (err) {
return reject(err);
}
resolve(data && data.executable && data.executable.number);
});
});
}
}
function waitForJobToFinish(jenkins, jobName, buildId, interval) {
return waitForJobToFinishInner(jobName)
.then((data) => {
if ('SUCCESS' === data.result) {
return data;
}
if (['ABORTED', 'FAILURE'].indexOf(data.result) > -1) {
const errorMessage = `JENKINS[${ jobName }:${ buildId }] job ${ data.result }`;
throw new Error(errorMessage);
}
return waitFor(interval)
.then(() => waitForJobToFinish(jenkins, jobName, buildId, interval));
});
function waitForJobToFinishInner(jobName) {
return new Promise((resolve, reject) => {
jenkins.build.get(jobName, buildId, function (err, data) {
if (err) {
return reject(err);
}
resolve(data);
});
});
}
}
function waitFor(interval) {
return new Promise((resolve) => setTimeout(() => resolve(), interval));
}
使用过滤器,我很难获取状态值,该状态值是数组内部的对象。