This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
task.go
92 lines (83 loc) · 3.14 KB
/
task.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package adminservice
import (
"context"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
"github.com/flyteorg/flytestdlib/logger"
"github.com/flyteorg/flyteadmin/pkg/rpc/adminservice/util"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (m *AdminService) CreateTask(
ctx context.Context,
request *admin.TaskCreateRequest) (*admin.TaskCreateResponse, error) {
defer m.interceptPanic(ctx, request)
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")
}
var response *admin.TaskCreateResponse
var err error
m.Metrics.taskEndpointMetrics.create.Time(func() {
response, err = m.TaskManager.CreateTask(ctx, *request)
})
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.taskEndpointMetrics.create)
}
m.Metrics.taskEndpointMetrics.create.Success()
return response, nil
}
func (m *AdminService) GetTask(ctx context.Context, request *admin.ObjectGetRequest) (*admin.Task, error) {
defer m.interceptPanic(ctx, request)
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")
}
// NOTE: When the Get HTTP endpoint is called the resource type is implicit (from the URL) so we must add it
// to the request.
if request.Id != nil && request.Id.ResourceType == core.ResourceType_UNSPECIFIED {
logger.Infof(ctx, "Adding resource type for unspecified value in request: [%+v]", request)
request.Id.ResourceType = core.ResourceType_TASK
}
var response *admin.Task
var err error
m.Metrics.taskEndpointMetrics.get.Time(func() {
response, err = m.TaskManager.GetTask(ctx, *request)
})
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.taskEndpointMetrics.get)
}
m.Metrics.taskEndpointMetrics.get.Success()
return response, nil
}
func (m *AdminService) ListTaskIds(
ctx context.Context, request *admin.NamedEntityIdentifierListRequest) (*admin.NamedEntityIdentifierList, error) {
defer m.interceptPanic(ctx, request)
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")
}
var response *admin.NamedEntityIdentifierList
var err error
m.Metrics.taskEndpointMetrics.listIds.Time(func() {
response, err = m.TaskManager.ListUniqueTaskIdentifiers(ctx, *request)
})
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.taskEndpointMetrics.listIds)
}
m.Metrics.taskEndpointMetrics.listIds.Success()
return response, nil
}
func (m *AdminService) ListTasks(ctx context.Context, request *admin.ResourceListRequest) (*admin.TaskList, error) {
defer m.interceptPanic(ctx, request)
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")
}
var response *admin.TaskList
var err error
m.Metrics.taskEndpointMetrics.list.Time(func() {
response, err = m.TaskManager.ListTasks(ctx, *request)
})
if err != nil {
return nil, util.TransformAndRecordError(err, &m.Metrics.taskEndpointMetrics.list)
}
m.Metrics.taskEndpointMetrics.list.Success()
return response, nil
}