9 type TaskResponse struct {
11 State ResponseState `json:"state"`
12 Response map[string]string `json:"response"`
14 RetryTime int64 `json:"retrytime"`
17 // Response related magic
19 func NewTaskResponse() (resp *TaskResponse) {
20 resp = new(TaskResponse)
21 resp.Response = make(map[string]string)
26 func (resp *TaskResponse) IsFinished() bool {
27 return resp.State.Finished()
30 func (resp *TaskResponse) DidFail() bool {
31 return resp.State.Failed()
34 func (resp *TaskResponse) CanRetry() bool {
35 return resp.State.CanRetry()
39 func ResponseFromProto(ptr *o.ProtoTaskResponse) (r *TaskResponse) {
42 switch (*(ptr.Status)) {
43 case o.ProtoTaskResponse_JOB_INPROGRESS:
44 r.State = RESP_RUNNING
45 case o.ProtoTaskResponse_JOB_SUCCESS:
46 r.State = RESP_FINISHED
47 case o.ProtoTaskResponse_JOB_FAILED:
49 case o.ProtoTaskResponse_JOB_HOST_FAILURE:
50 r.State = RESP_FAILED_HOST_ERROR
51 case o.ProtoTaskResponse_JOB_UNKNOWN:
52 r.State = RESP_FAILED_UNKNOWN_SCORE
53 case o.ProtoTaskResponse_JOB_UNKNOWN_FAILURE:
56 r.State = RESP_FAILED_UNKNOWN
60 r.Response = o.MapFromProtoJobParameters(ptr.Response)
65 func (resp *TaskResponse) Encode() (ptr *o.ProtoTaskResponse) {
66 ptr = new(o.ProtoTaskResponse)
70 ptr.Status = o.NewProtoTaskResponse_TaskStatus(o.ProtoTaskResponse_JOB_INPROGRESS)
72 ptr.Status = o.NewProtoTaskResponse_TaskStatus(o.ProtoTaskResponse_JOB_SUCCESS)
74 ptr.Status = o.NewProtoTaskResponse_TaskStatus(o.ProtoTaskResponse_JOB_FAILED)
75 case RESP_FAILED_UNKNOWN_SCORE:
76 ptr.Status = o.NewProtoTaskResponse_TaskStatus(o.ProtoTaskResponse_JOB_UNKNOWN)
77 case RESP_FAILED_HOST_ERROR:
78 ptr.Status = o.NewProtoTaskResponse_TaskStatus(o.ProtoTaskResponse_JOB_HOST_FAILURE)
79 case RESP_FAILED_UNKNOWN:
80 ptr.Status = o.NewProtoTaskResponse_TaskStatus(o.ProtoTaskResponse_JOB_UNKNOWN_FAILURE)
84 ptr.Response = o.ProtoJobParametersFromMap(resp.Response)