-
Notifications
You must be signed in to change notification settings - Fork 151
/
list.go
41 lines (30 loc) · 1.01 KB
/
list.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
package workers
import (
"time"
"github.com/labstack/echo/v4"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/transformers"
"github.com/hatchet-dev/hatchet/pkg/repository"
"github.com/hatchet-dev/hatchet/pkg/repository/prisma/db"
)
func (t *WorkerService) WorkerList(ctx echo.Context, request gen.WorkerListRequestObject) (gen.WorkerListResponseObject, error) {
tenant := ctx.Get("tenant").(*db.TenantModel)
sixSecAgo := time.Now().Add(-24 * time.Hour)
workers, err := t.config.APIRepository.Worker().ListWorkers(tenant.ID, &repository.ListWorkersOpts{
LastHeartbeatAfter: &sixSecAgo,
})
if err != nil {
return nil, err
}
rows := make([]gen.Worker, len(workers))
for i, worker := range workers {
workerCp := worker
slots := int(worker.RemainingSlots)
rows[i] = *transformers.ToWorkerSqlc(&workerCp.Worker, &slots, &workerCp.WebhookUrl.String, nil)
}
return gen.WorkerList200JSONResponse(
gen.WorkerList{
Rows: &rows,
},
), nil
}