mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
the mqs are storing a models.Task, which was not incorporating all the fields that are in a task.Config. I would very much like to merge these two things, but expect to do this in a future restructuring as both are used widely and not cordoned off properly (Config has a channel, stdin, stdout, stderr -- and isn't just a 'config', so to speak, as Task is). Since a task.Config is what is used to actually run a container, the result of the aforementioned deficiency was #193 where tasks are improperly configured and ran (namely, memory wrong). async tasks can still not be hot, they will be reverted to default format. would also like to fix this (also part of restructuring). I actually started doing this, hence the changes to those files (the surface area of the change is small and discourages improper future use, so I've left what I've done). this will: closes #193 closes #195 closes #154 removes many unused fields in models.Task, since we have not implemented retries. priority & delay are left, even though they are not used either, the main goal of this is to resolve #193 and both these fields are strongly plumbed into all the mqs, so punting on those two.
103 lines
3.0 KiB
Go
103 lines
3.0 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
strfmt "github.com/go-openapi/strfmt"
|
|
"github.com/go-openapi/swag"
|
|
|
|
"github.com/go-openapi/validate"
|
|
)
|
|
|
|
// TODO get rid of this. id and status are not more coupled than anything else?
|
|
// burn it at the stake
|
|
|
|
/*IDStatus Id status
|
|
|
|
swagger:model IdStatus
|
|
*/
|
|
type IDStatus struct {
|
|
|
|
/* Unique identifier representing a specific task.
|
|
|
|
Read Only: true
|
|
*/
|
|
ID string `json:"id,omitempty"`
|
|
|
|
/* States and valid transitions.
|
|
|
|
+---------+
|
|
+---------> delayed <----------------+
|
|
+----+----+ |
|
|
| |
|
|
| |
|
|
+----v----+ |
|
|
+---------> queued <----------------+
|
|
+----+----+ *
|
|
| *
|
|
| retry * creates new task
|
|
+----v----+ *
|
|
| running | *
|
|
+--+-+-+--+ |
|
|
+---------|-|-|-----+-------------+
|
|
+---|---------+ | +-----|---------+ |
|
|
| | | | | |
|
|
+-----v---^-+ +--v-------^+ +--v---^-+
|
|
| success | | cancelled | | error |
|
|
+-----------+ +-----------+ +--------+
|
|
|
|
* delayed - has a delay.
|
|
* queued - Ready to be consumed when it's turn comes.
|
|
* running - Currently consumed by a runner which will attempt to process it.
|
|
* success - (or complete? success/error is common javascript terminology)
|
|
* error - Something went wrong. In this case more information can be obtained
|
|
by inspecting the "reason" field.
|
|
- timeout
|
|
- killed - forcibly killed by worker due to resource restrictions or access
|
|
violations.
|
|
- bad_exit - exited with non-zero status due to program termination/crash.
|
|
* cancelled - cancelled via API. More information in the reason field.
|
|
- client_request - Request was cancelled by a client.
|
|
|
|
|
|
Read Only: true
|
|
*/
|
|
Status string `json:"status,omitempty"`
|
|
}
|
|
|
|
// Validate validates this Id status
|
|
func (m *IDStatus) Validate(formats strfmt.Registry) error { return m.validateStatus(formats) }
|
|
|
|
var idStatusTypeStatusPropEnum []interface{}
|
|
|
|
// prop value enum
|
|
func (m *IDStatus) validateStatusEnum(path, location string, value string) error {
|
|
if idStatusTypeStatusPropEnum == nil {
|
|
var res []string
|
|
if err := json.Unmarshal([]byte(`["delayed","queued","running","success","error","cancelled"]`), &res); err != nil {
|
|
return err
|
|
}
|
|
for _, v := range res {
|
|
idStatusTypeStatusPropEnum = append(idStatusTypeStatusPropEnum, v)
|
|
}
|
|
}
|
|
if err := validate.Enum(path, location, value, idStatusTypeStatusPropEnum); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *IDStatus) validateStatus(formats strfmt.Registry) error {
|
|
|
|
if swag.IsZero(m.Status) { // not required
|
|
return nil
|
|
}
|
|
|
|
// value enum
|
|
if err := m.validateStatusEnum("status", "body", m.Status); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|