github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/api/models/task.go (about) 1 package models 2 3 // This file was generated by the swagger tool. 4 // Editing this file might prove futile when you re-run the swagger generate command 5 6 import ( 7 "encoding/json" 8 9 strfmt "github.com/go-openapi/strfmt" 10 11 "github.com/go-openapi/errors" 12 "github.com/go-openapi/validate" 13 ) 14 15 const ( 16 // TypeNone ... 17 TypeNone = "" 18 // TypeSync ... 19 TypeSync = "sync" 20 // TypeAsync ... 21 TypeAsync = "async" 22 ) 23 24 const ( 25 // FormatDefault ... 26 FormatDefault = "default" 27 // FormatHTTP ... 28 FormatHTTP = "http" 29 ) 30 31 /*Task task 32 33 swagger:model Task 34 */ 35 type Task struct { 36 NewTask 37 38 IDStatus 39 40 /* Time when task completed, whether it was successul or failed. Always in UTC. 41 */ 42 CompletedAt strfmt.DateTime `json:"completed_at,omitempty"` 43 44 /* Time when task was submitted. Always in UTC. 45 46 Read Only: true 47 */ 48 CreatedAt strfmt.DateTime `json:"created_at,omitempty"` 49 50 /* Env vars for the task. Comes from the ones set on the Route. 51 */ 52 EnvVars map[string]string `json:"env_vars,omitempty"` 53 54 /* The error message, if status is 'error'. This is errors due to things outside the task itself. Errors from user code will be found in the log. 55 */ 56 Error string `json:"error,omitempty"` 57 58 /* App this task belongs to. 59 60 Read Only: true 61 */ 62 AppName string `json:"app_name,omitempty"` 63 64 Path string `json:"path"` 65 66 /* Machine usable reason for task being in this state. 67 Valid values for error status are `timeout | killed | bad_exit`. 68 Valid values for cancelled status are `client_request`. 69 For everything else, this is undefined. 70 71 */ 72 Reason string `json:"reason,omitempty"` 73 74 /* If this field is set, then this task was retried by the task referenced in this field. 75 76 Read Only: true 77 */ 78 RetryAt string `json:"retry_at,omitempty"` 79 80 /* If this field is set, then this task is a retry of the ID in this field. 81 82 Read Only: true 83 */ 84 RetryOf string `json:"retry_of,omitempty"` 85 86 /* Time when task started execution. Always in UTC. 87 */ 88 StartedAt strfmt.DateTime `json:"started_at,omitempty"` 89 } 90 91 // Validate validates this task 92 func (m *Task) Validate(formats strfmt.Registry) error { 93 var res []error 94 95 if err := m.NewTask.Validate(formats); err != nil { 96 res = append(res, err) 97 } 98 99 if err := m.IDStatus.Validate(formats); err != nil { 100 res = append(res, err) 101 } 102 103 if err := m.validateEnvVars(formats); err != nil { 104 res = append(res, err) 105 } 106 107 if err := m.validateReason(formats); err != nil { 108 res = append(res, err) 109 } 110 111 if len(res) > 0 { 112 return errors.CompositeValidationError(res...) 113 } 114 return nil 115 } 116 117 func (m *Task) validateEnvVars(formats strfmt.Registry) error { 118 119 if err := validate.Required("env_vars", "body", m.EnvVars); err != nil { 120 return err 121 } 122 123 return nil 124 } 125 126 var taskTypeReasonPropEnum []interface{} 127 128 // property enum 129 func (m *Task) validateReasonEnum(path, location string, value string) error { 130 if taskTypeReasonPropEnum == nil { 131 var res []string 132 if err := json.Unmarshal([]byte(`["timeout","killed","bad_exit","client_request"]`), &res); err != nil { 133 return err 134 } 135 for _, v := range res { 136 taskTypeReasonPropEnum = append(taskTypeReasonPropEnum, v) 137 } 138 } 139 if err := validate.Enum(path, location, value, taskTypeReasonPropEnum); err != nil { 140 return err 141 } 142 return nil 143 } 144 145 func (m *Task) validateReason(formats strfmt.Registry) error { 146 147 // value enum 148 if err := m.validateReasonEnum("reason", "body", m.Reason); err != nil { 149 return err 150 } 151 152 return nil 153 }