Skip to content

Commit

Permalink
change batch chart loads
Browse files Browse the repository at this point in the history
  • Loading branch information
PhoenixNazarov committed Oct 23, 2024
1 parent d322b8b commit 53e47a8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
41 changes: 22 additions & 19 deletions client/src/stores/healthcheck.store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {defineStore} from "pinia";
import {BaseEntity} from "./config/abstractStoreFactory.ts";
import {ApiService} from "../api/ApiService.ts";
import {chunk} from "../views/Utils.ts";

export interface HealthTarget extends BaseEntity {
url: string
Expand All @@ -18,12 +17,9 @@ export interface HealthDay extends BaseEntity {
}

export interface HealthUnit extends BaseEntity {
request_datetime: string
request_datetime: number
status: boolean
response_time: number

health_target_id: number
collect: boolean
}

export const useHealthCheckStore = defineStore({
Expand Down Expand Up @@ -69,7 +65,9 @@ export const useHealthCheckStore = defineStore({
this.loadDays(this.targets),
]
)
this.loadUnits(this.targets).then()
this.targets.forEach(
t => this.loadUnits(t).then()
)
}
this.loadings.targets = false
},
Expand All @@ -84,19 +82,24 @@ export const useHealthCheckStore = defineStore({
}
)
},
async loadUnits(healthTargets: HealthTarget[]) {
for (const targets of chunk(healthTargets, 1)) {
console.log(targets)
const units = await ApiService.post<HealthUnit[]>(`/api/healthcheck/units/load`, {targets_ids: targets.map(el => el.id)})
if (units == undefined) continue;
units.forEach(
el => {
const hDays = this.units.get(el.health_target_id) || []
hDays.push(el)
this.units.set(el.health_target_id, hDays)
}
)
}
async loadUnits(healthTarget: HealthTarget) {
if (healthTarget.id == undefined) return
const units = await ApiService.post<[number, boolean, number][]>(`/api/healthcheck/units/load`, {targets_id: healthTarget.id})
if (units == undefined) return
const hDays = this.units.get(healthTarget.id) || []
units.forEach(
el => {
hDays.push(
{
request_datetime: el[2],
status: el[1],
response_time: el[0],
}
)
}
)
this.units.set(healthTarget.id, hDays)

}
}
}
Expand Down
Empty file.

This file was deleted.

9 changes: 6 additions & 3 deletions server/promptadmin_server/api/service/healthcheck_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def load_last_days(self, targets_ids: list[int], days: int = 90):
)
return await self.health_day_service.find_by_view_params(view_params)

async def load_units(self, target_ids: list[int]):
async def load_units(self, target_id: int) -> list[tuple[float, bool, float]]:
old_date = datetime.datetime.now() - datetime.timedelta(hours=12)
view_params = (
ViewParamsBuilder()
Expand All @@ -60,11 +60,14 @@ async def load_units(self, target_ids: list[int]):
)
)
.filter(
ViewParamsFilter(field=HealthUnit.health_target_id, value=target_ids)
ViewParamsFilter(field=HealthUnit.health_target_id, value=target_id)
)
.build()
)
return await self.health_unit_service.find_by_view_params(view_params)
return [
(i.response_time, i.status, i.request_datetime.timestamp())
for i in await self.health_unit_service.find_by_view_params(view_params)
]

async def create_target(self, url: str, label: str) -> HealthTarget:
pass

0 comments on commit 53e47a8

Please sign in to comment.