-
Notifications
You must be signed in to change notification settings - Fork 568
/
pps.go
66 lines (52 loc) · 1.57 KB
/
pps.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
package pps
import (
"fmt"
"regexp"
"github.com/pachyderm/pachyderm/v2/src/internal/grpcutil"
"github.com/pachyderm/pachyderm/v2/src/pps"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// ErrJobFinished represents a finished job error.
type ErrJobFinished struct {
Job *pps.Job
}
func (e ErrJobFinished) Error() string {
return fmt.Sprintf("job %v has already finished", e.Job)
}
type ErrPipelineNotFound struct {
Pipeline *pps.Pipeline
}
func (e ErrPipelineNotFound) Error() string {
return fmt.Sprintf("pipeline %q not found", e.Pipeline)
}
func (e ErrPipelineNotFound) GRPCStatus() *status.Status {
return status.New(codes.NotFound, e.Error())
}
type ErrPipelineAlreadyExists struct {
Pipeline *pps.Pipeline
}
func (e ErrPipelineAlreadyExists) Error() string {
return fmt.Sprintf("pipeline %q already exists", e.Pipeline)
}
func (e ErrPipelineAlreadyExists) GRPCStatus() *status.Status {
return status.New(codes.AlreadyExists, e.Error())
}
var (
jobFinishedRe = regexp.MustCompile("job [^ ]+ has already finished")
pipelineNotFoundRe = regexp.MustCompile("pipeline [^ ]+ not found")
)
// IsJobFinishedErr returns true if 'err' has an error message that matches ErrJobFinished
func IsJobFinishedErr(err error) bool {
if err == nil {
return false
}
return jobFinishedRe.MatchString(grpcutil.ScrubGRPC(err).Error())
}
// IsPipelineNotFoundErr returns true if 'err' has an error message that matches ErrJobFinished
func IsPipelineNotFoundErr(err error) bool {
if err == nil {
return false
}
return pipelineNotFoundRe.MatchString(err.Error())
}