File: job.go

package info (click to toggle)
golang-github-mimuret-golang-iij-dpf 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,340 kB
  • sloc: makefile: 55
file content (53 lines) | stat: -rw-r--r-- 1,248 bytes parent folder | download
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
package core

import (
	"fmt"

	"github.com/mimuret/golang-iij-dpf/pkg/api"
	"github.com/mimuret/golang-iij-dpf/pkg/apis"
)

type JobStatus string

var _ apis.Spec = &Job{}

const (
	JobStatusRunning    JobStatus = "RUNNING"
	JobStatusSuccessful JobStatus = "SUCCESSFUL"
	JobStatusFailed     JobStatus = "FAILED"
)

func (c JobStatus) String() string { return string(c) }

// +k8s:deepcopy-gen:interfaces=github.com/mimuret/golang-iij-dpf/pkg/api.Object
type Job struct {
	AttributeMeta
	RequestID    string    `read:"request_id"`
	Status       JobStatus `read:"status"`
	ResourceUrl  string    `read:"resources_url"`
	ErrorType    string    `read:"error_type"`
	ErrorMessage string    `read:"error_message"`
}

func (c *Job) GetError() error {
	if c.Status == JobStatusFailed {
		return fmt.Errorf("ErrorType: %s Messages %s", c.ErrorType, c.ErrorMessage)
	}
	return nil
}

func (c *Job) GetName() string { return "jobs" }
func (c *Job) GetPathMethod(action api.Action) (string, string) {
	if action == api.ActionRead {
		return action.ToMethod(), fmt.Sprintf("/jobs/%s", c.RequestID)
	}
	return "", ""
}

func (c *Job) SetPathParams(args ...interface{}) error {
	return apis.SetPathParams(args, &c.RequestID)
}

func init() {
	register(&Job{})
}