-
Notifications
You must be signed in to change notification settings - Fork 145
/
get_metrics.go
44 lines (33 loc) · 1.21 KB
/
get_metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package workflows
import (
"errors"
"github.com/labstack/echo/v4"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/apierrors"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
"github.com/hatchet-dev/hatchet/pkg/repository"
"github.com/hatchet-dev/hatchet/pkg/repository/prisma/db"
)
func (t *WorkflowService) WorkflowGetMetrics(ctx echo.Context, request gen.WorkflowGetMetricsRequestObject) (gen.WorkflowGetMetricsResponseObject, error) {
tenant := ctx.Get("tenant").(*db.TenantModel)
workflow := ctx.Get("workflow").(*db.WorkflowModel)
opts := &repository.GetWorkflowMetricsOpts{}
if request.Params.Status != nil {
opts.Status = (*string)(request.Params.Status)
}
if request.Params.GroupKey != nil {
opts.GroupKey = request.Params.GroupKey
}
metrics, err := t.config.APIRepository.Workflow().GetWorkflowMetrics(tenant.ID, workflow.ID, opts)
if err != nil {
if errors.Is(err, db.ErrNotFound) {
return gen.WorkflowGetMetrics404JSONResponse(
apierrors.NewAPIErrors("workflow not found"),
), nil
}
return nil, err
}
return gen.WorkflowGetMetrics200JSONResponse(gen.WorkflowMetrics{
GroupKeyCount: &metrics.GroupKeyCount,
GroupKeyRunsCount: &metrics.GroupKeyRunsCount,
}), nil
}