mirror of
https://github.com/amir20/dozzle.git
synced 2026-01-04 20:14:59 +01:00
chore: cleans up types in typescript (#2335)
This commit is contained in:
@@ -8,7 +8,7 @@ type Stat = Omit<ContainerStat, "id">;
|
||||
const SWARM_ID_REGEX = /(\.[a-z0-9]{25})+$/i;
|
||||
|
||||
export class Container {
|
||||
public stat: Ref<Stat>;
|
||||
private _stat: Ref<Stat>;
|
||||
private readonly throttledStatHistory: UseThrottledRefHistoryReturn<Stat, Stat>;
|
||||
public readonly swarmId: string | null = null;
|
||||
public readonly isSwarm: boolean = false;
|
||||
@@ -25,9 +25,9 @@ export class Container {
|
||||
public state: ContainerState,
|
||||
public health?: ContainerHealth,
|
||||
) {
|
||||
this.stat = ref({ cpu: 0, memory: 0, memoryUsage: 0 });
|
||||
this.throttledStatHistory = useThrottledRefHistory(this.stat, { capacity: 300, deep: true, throttle: 1000 });
|
||||
this.movingAverageStat = useExponentialMovingAverage(this.stat, 0.2);
|
||||
this._stat = ref({ cpu: 0, memory: 0, memoryUsage: 0 });
|
||||
this.throttledStatHistory = useThrottledRefHistory(this._stat, { capacity: 300, deep: true, throttle: 1000 });
|
||||
this.movingAverageStat = useExponentialMovingAverage(this._stat, 0.2);
|
||||
|
||||
const match = name.match(SWARM_ID_REGEX);
|
||||
if (match) {
|
||||
@@ -37,15 +37,24 @@ export class Container {
|
||||
}
|
||||
}
|
||||
|
||||
public getStatHistory() {
|
||||
get statHistory() {
|
||||
return unref(this.throttledStatHistory.history);
|
||||
}
|
||||
|
||||
public getLastStat() {
|
||||
return unref(this.throttledStatHistory.last);
|
||||
}
|
||||
|
||||
get movingAverage() {
|
||||
return unref(this.movingAverageStat);
|
||||
}
|
||||
|
||||
get stat() {
|
||||
return unref(this._stat);
|
||||
}
|
||||
|
||||
public updateStat(stat: Stat) {
|
||||
if (isRef(this._stat)) {
|
||||
this._stat.value = stat;
|
||||
} else {
|
||||
// @ts-ignore
|
||||
this._stat = stat;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user