1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/didiopensource-KnowStreaming

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Это зеркальный репозиторий, синхронизируется ежедневно с исходного репозитория.
Клонировать/Скачать
admin-monitor.ts 2.3 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
孙超 Отправлено 4 лет назад 6080f76
import { observable, action } from 'mobx';
import { getBrokersMetricsHistory } from 'lib/api';
import { IClusterMetrics } from 'types/base-type';
const STATUS = {
PENDING: 'pending',
REJECT: 'reject',
FULLFILLED: 'fullfilled'
}
class AdminMonitor {
@observable
public currentClusterId = null as number;
@observable
public currentBrokerId = null as number;
@observable
public brokersMetricsHistory: IClusterMetrics[];
public requestId = null as any;
@action.bound
public setCurrentClusterId(clusterId: number) {
this.currentClusterId = clusterId;
}
@action.bound
public setCurrentBrokerId(brokeId: number) {
this.currentBrokerId = brokeId;
}
@action.bound
public setRequestId(requestId: any) {
this.requestId = requestId;
}
@action.bound
public setBrokersChartsData(data: IClusterMetrics[]) {
this.brokersMetricsHistory = data;
this.setRequestId(STATUS.FULLFILLED);
Promise.all(this.taskQueue).then(() => {
this.setRequestId(null);
this.taskQueue = [];
})
return data;
}
public taskQueue = [] as any[];
public getBrokersMetricsList = async (startTime: string, endTime: string) => {
if (this.requestId) {
//逐条定时查询任务状态
const p = new Promise((res, rej) => {
const timer = window.setInterval(() => {
if (this.requestId === STATUS.REJECT) {
rej(this.brokersMetricsHistory);
window.clearInterval(timer);
} else if (this.requestId === STATUS.FULLFILLED) {
res(this.brokersMetricsHistory);
window.clearInterval(timer);
}
}, (this.taskQueue.length + 1) * 100);
});
this.taskQueue.push(p);
return p;
}
this.setRequestId(STATUS.PENDING);
return getBrokersMetricsHistory(this.currentClusterId, this.currentBrokerId, startTime, endTime)
.then(this.setBrokersChartsData).catch(() => this.setRequestId(STATUS.REJECT));
}
public getBrokersChartsData = async (startTime: string, endTime: string, reload?: boolean) => {
if (this.brokersMetricsHistory && !reload) {
return new Promise(res => res(this.brokersMetricsHistory));
}
return this.getBrokersMetricsList(startTime, endTime);
}
}
export const adminMonitor = new AdminMonitor();

Комментарий ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/didiopensource-KnowStreaming.git
git@gitlife.ru:oschina-mirror/didiopensource-KnowStreaming.git
oschina-mirror
didiopensource-KnowStreaming
didiopensource-KnowStreaming
v2.4.1