// 查状态 checkStatus(test_plan_info): void { const selectData = test_plan_info; // 过滤出和this.modelData中和test_plan_info中test_application_sample_no相等的数据 const modelDataCopy = this.modelData.filter((v) => { return selectData.some((item) => item.test_application_sample_no === v.test_application_sample_no && v.file_info.length > 0); }); console.log(modelDataCopy,'modelDataCopy'); interval(10000) .pipe( takeUntil(this.stopPolling$), mergeMap(() => modelDataCopy), mergeMap(async (item) => this.callApi({ inspection_no: item.inspection_no, analysis_model_no: item.analysis_model_no, test_application_sample_no: item.test_application_sample_no, }) ) ) .subscribe((result) => { // 0:未开始 1:进行中 2:成功 3:失败 const status = result.callApiRes.model_list[0].analysis_state // selectData 如果有成功的,则对应改变selectData的状态,和删除this.modelData中的数据 const analysis_status = result.callApiRes.model_list[0].analysis_state; const analysis_msg = result.callApiRes.model_list[0].analysis_msg; for (const item of selectData) { if ( item.test_application_sample_no === result.test_application_sample_no && analysis_status === '2' ) { item['pass'] = true; item['analysis_msg'] = analysis_msg; } if ( item.test_application_sample_no === result.test_application_sample_no && analysis_status === '3' ) { const hasPass = 'pass' in item; if (!hasPass) { item['pass'] = false; item['analysis_msg'] = analysis_msg; } } } // 判断selectData的每一个数据是否都包含pass属性,如果都包含,则停止轮询 const isAllPass = selectData.every((item) => 'pass' in item); if (isAllPass) { this.stopPolling$.next(); this.submitDataContain(selectData); } }); // 在15分钟后停止轮询 setTimeout(() => { this.stopPolling$.next(); this.submitDataContain(selectData); }, 15 * 60 * 1000); } async callApi(value) { return await this.testTaskImplementService .getEchartsInfo({ model_list: [ { inspection_no: value.inspection_no ? value.inspection_no : this.inspection_no, analysis_model_no: value.analysis_model_no, }, ], }) .then((res) => { return { test_application_sample_no: value.test_application_sample_no, callApiRes: res, }; }); }
标签:application,轮训,no,analysis,sample,item,任务,test,angular From: https://www.cnblogs.com/cai-xin/p/17422330.html