mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-27 05:49:04 +01:00
Add AddJobCount() for analysis view
This commit is contained in:
parent
3d75f0ef3c
commit
edb1b47281
@ -284,7 +284,12 @@ func (r *queryResolver) JobsStatistics(ctx context.Context, filter []*model.JobF
|
|||||||
stats, err = r.Repo.AddJobCountGrouped(ctx, filter, groupBy, stats, "running")
|
stats, err = r.Repo.AddJobCountGrouped(ctx, filter, groupBy, stats, "running")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("Job counts only implemented with groupBy argument")
|
if requireField(ctx, "shortJobs") {
|
||||||
|
stats, err = r.Repo.AddJobCount(ctx, filter, stats, "short")
|
||||||
|
}
|
||||||
|
if requireField(ctx, "RunningJobs") {
|
||||||
|
stats, err = r.Repo.AddJobCount(ctx, filter, stats, "running")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -304,6 +304,49 @@ func (r *JobRepository) AddJobCountGrouped(
|
|||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *JobRepository) AddJobCount(
|
||||||
|
ctx context.Context,
|
||||||
|
filter []*model.JobFilter,
|
||||||
|
stats []*model.JobsStatistics,
|
||||||
|
kind string) ([]*model.JobsStatistics, error) {
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
|
query := r.buildCountQuery(filter, kind, "")
|
||||||
|
query, err := SecurityCheck(ctx, query)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
rows, err := query.RunWith(r.DB).Query()
|
||||||
|
if err != nil {
|
||||||
|
log.Warn("Error while querying DB for job statistics")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
counts := make(map[string]int)
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var cnt sql.NullInt64
|
||||||
|
if err := rows.Scan(&cnt); err != nil {
|
||||||
|
log.Warn("Error while scanning rows")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch kind {
|
||||||
|
case "running":
|
||||||
|
for _, s := range stats {
|
||||||
|
s.RunningJobs = counts[s.ID]
|
||||||
|
}
|
||||||
|
case "short":
|
||||||
|
for _, s := range stats {
|
||||||
|
s.ShortJobs = counts[s.ID]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Timer JobStatistics %s", time.Since(start))
|
||||||
|
return stats, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *JobRepository) AddHistograms(
|
func (r *JobRepository) AddHistograms(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
filter []*model.JobFilter,
|
filter []*model.JobFilter,
|
||||||
|
Loading…
Reference in New Issue
Block a user