mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Initial work on async functions
This commit is contained in:
30
api/models/complete.go
Normal file
30
api/models/complete.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package models
|
||||
|
||||
import "github.com/go-openapi/strfmt"
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
/*Complete complete
|
||||
|
||||
swagger:model Complete
|
||||
*/
|
||||
type Complete struct {
|
||||
|
||||
/* Time when task was completed. Always in UTC.
|
||||
*/
|
||||
CompletedAt strfmt.DateTime `json:"completed_at,omitempty"`
|
||||
|
||||
/* Error message, if status=error. Only used by the /error endpoint.
|
||||
*/
|
||||
Error string `json:"error,omitempty"`
|
||||
|
||||
/* Machine readable reason failure, if status=error. Only used by the /error endpoint.
|
||||
*/
|
||||
Reason string `json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this complete
|
||||
func (m *Complete) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
71
api/models/group.go
Normal file
71
api/models/group.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
/*Group group
|
||||
|
||||
swagger:model Group
|
||||
*/
|
||||
type Group struct {
|
||||
|
||||
/* Time when image first used/created.
|
||||
|
||||
Read Only: true
|
||||
*/
|
||||
CreatedAt strfmt.DateTime `json:"created_at,omitempty"`
|
||||
|
||||
/* User defined environment variables that will be passed in to each task in this group.
|
||||
*/
|
||||
EnvVars map[string]string `json:"env_vars,omitempty"`
|
||||
|
||||
/* Name of Docker image to use in this group. You should include the image tag, which should be a version number, to be more accurate. Can be overridden on a per task basis with task.image.
|
||||
*/
|
||||
Image string `json:"image,omitempty"`
|
||||
|
||||
/* The maximum number of tasks that will run at the exact same time in this group.
|
||||
*/
|
||||
MaxConcurrency int32 `json:"max_concurrency,omitempty"`
|
||||
|
||||
/* Name of this group. Must be different than the image name. Can ony contain alphanumeric, -, and _.
|
||||
|
||||
Read Only: true
|
||||
*/
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this group
|
||||
func (m *Group) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateEnvVars(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Group) validateEnvVars(formats strfmt.Registry) error {
|
||||
|
||||
if swag.IsZero(m.EnvVars) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := validate.Required("env_vars", "body", m.EnvVars); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
50
api/models/group_wrapper.go
Normal file
50
api/models/group_wrapper.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
)
|
||||
|
||||
/*GroupWrapper group wrapper
|
||||
|
||||
swagger:model GroupWrapper
|
||||
*/
|
||||
type GroupWrapper struct {
|
||||
|
||||
/* group
|
||||
|
||||
Required: true
|
||||
*/
|
||||
Group *Group `json:"group"`
|
||||
}
|
||||
|
||||
// Validate validates this group wrapper
|
||||
func (m *GroupWrapper) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateGroup(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *GroupWrapper) validateGroup(formats strfmt.Registry) error {
|
||||
|
||||
if m.Group != nil {
|
||||
|
||||
if err := m.Group.Validate(formats); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
48
api/models/groups_wrapper.go
Normal file
48
api/models/groups_wrapper.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
/*GroupsWrapper groups wrapper
|
||||
|
||||
swagger:model GroupsWrapper
|
||||
*/
|
||||
type GroupsWrapper struct {
|
||||
|
||||
/* groups
|
||||
|
||||
Required: true
|
||||
*/
|
||||
Groups []*Group `json:"groups"`
|
||||
}
|
||||
|
||||
// Validate validates this groups wrapper
|
||||
func (m *GroupsWrapper) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateGroups(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *GroupsWrapper) validateGroups(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("groups", "body", m.Groups); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
115
api/models/id_status.go
Normal file
115
api/models/id_status.go
Normal file
@@ -0,0 +1,115 @@
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
"github.com/go-openapi/swag"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
/*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 {
|
||||
var res []error
|
||||
|
||||
if err := m.validateStatus(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
52
api/models/mq.go
Normal file
52
api/models/mq.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package models
|
||||
|
||||
// Titan uses a Message Queue to impose a total ordering on jobs that it will
|
||||
// execute in order. Tasks are added to the queue via the Push() interface. The
|
||||
// MQ must support a reserve-delete 2 step dequeue to allow Titan to implement
|
||||
// timeouts and retries.
|
||||
//
|
||||
// The Reserve() operation must return a job based on this total ordering
|
||||
// (described below). At this point, the MQ backend must start a timeout on the
|
||||
// job. If Delete() is not called on the Task within the timeout, the Task should
|
||||
// be restored to the queue.
|
||||
//
|
||||
// Total ordering: The queue should maintain an ordering based on priority and
|
||||
// logical time. Priorities are currently 0-2 and available in the Task's
|
||||
// priority field. Tasks with higher priority always get pulled off the queue
|
||||
// first. Within the same priority, jobs should be available in FIFO order.
|
||||
|
||||
// When a job is required to be restored to the queue, it should maintain it's
|
||||
// approximate order in the queue. That is, for jobs [A, B, C], with A being
|
||||
// the head of the queue:
|
||||
// Reserve() leads to A being passed to a consumer, and timeout started.
|
||||
// Next Reserve() leads to B being dequeued. This consumer finishes running the
|
||||
// task, leading to Delete() being called. B is now permanently erased from the
|
||||
// queue.
|
||||
// A's timeout occurs before the job is finished. At this point the ordering
|
||||
// should be [A, C] and not [C, A].
|
||||
type MessageQueue interface {
|
||||
// Push a Task onto the queue. If any error is returned, the Task SHOULD not be
|
||||
// queued. Note that this does not completely avoid double queueing, that is
|
||||
// OK, Titan will perform a check against the datastore after a dequeue.
|
||||
//
|
||||
// If the job's Delay value is > 0, the job should NOT be enqueued. The job
|
||||
// should only be available in the queue after at least Delay seconds have
|
||||
// elapsed. No ordering is required among multiple jobs queued with similar
|
||||
// delays. That is, if jobs {A, C} are queued at t seconds, both with Delay
|
||||
// = 5 seconds, and the same priority, then they may be available on the
|
||||
// queue as [C, A] or [A, C].
|
||||
Push(*Task) (*Task, error)
|
||||
|
||||
// Remove a job from the front of the queue, reserve it for a timeout and
|
||||
// return it. MQ implementations MUST NOT lose jobs in case of errors. That
|
||||
// is, in case of reservation failure, it should be possible to retrieve the
|
||||
// job on a future reservation.
|
||||
Reserve() (*Task, error)
|
||||
|
||||
// If a reservation is pending, consider it acknowledged and delete it. If
|
||||
// the job does not have an outstanding reservation, error. If a job did not
|
||||
// exist, succeed.
|
||||
Delete(*Task) error
|
||||
}
|
||||
|
||||
type Enqueue func(*Task) (*Task, error)
|
||||
95
api/models/new_job.go
Normal file
95
api/models/new_job.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
/*NewJob new job
|
||||
|
||||
swagger:model NewJob
|
||||
*/
|
||||
type NewJob struct {
|
||||
|
||||
/* Number of seconds to wait before queueing the job for consumption for the first time. Must be a positive integer. Jobs with a delay start in state "delayed" and transition to "running" after delay seconds.
|
||||
*/
|
||||
Delay int32 `json:"delay,omitempty"`
|
||||
|
||||
/* Name of Docker image to use. This is optional and can be used to override the image defined at the group level.
|
||||
|
||||
Required: true
|
||||
*/
|
||||
Image *string `json:"image"`
|
||||
|
||||
/* "Number of automatic retries this job is allowed. A retry will be attempted if a task fails. Max 25. Automatic retries are performed by titan when a task reaches a failed state and has `max_retries` > 0. A retry is performed by queueing a new job with the same image id and payload. The new job's max_retries is one less than the original. The new job's `retry_of` field is set to the original Job ID. Titan will delay the new job for retries_delay seconds before queueing it. Cancelled or successful tasks are never automatically retried."
|
||||
|
||||
*/
|
||||
MaxRetries int32 `json:"max_retries,omitempty"`
|
||||
|
||||
/* Payload for the job. This is what you pass into each job to make it do something.
|
||||
*/
|
||||
Payload string `json:"payload,omitempty"`
|
||||
|
||||
/* Priority of the job. Higher has more priority. 3 levels from 0-2. Jobs at same priority are processed in FIFO order.
|
||||
|
||||
Required: true
|
||||
*/
|
||||
Priority *int32 `json:"priority"`
|
||||
|
||||
/* Time in seconds to wait before retrying the job. Must be a non-negative integer.
|
||||
*/
|
||||
RetriesDelay *int32 `json:"retries_delay,omitempty"`
|
||||
|
||||
/* Maximum runtime in seconds. If a consumer retrieves the
|
||||
job, but does not change it's status within timeout seconds, the job
|
||||
is considered failed, with reason timeout (Titan may allow a small
|
||||
grace period). The consumer should also kill the job after timeout
|
||||
seconds. If a consumer tries to change status after Titan has already
|
||||
timed out the job, the consumer will be ignored.
|
||||
|
||||
*/
|
||||
Timeout *int32 `json:"timeout,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this new job
|
||||
func (m *NewJob) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateImage(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validatePriority(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *NewJob) validateImage(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("image", "body", m.Image); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *NewJob) validatePriority(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("priority", "body", m.Priority); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
48
api/models/new_jobs_wrapper.go
Normal file
48
api/models/new_jobs_wrapper.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
/*NewJobsWrapper new jobs wrapper
|
||||
|
||||
swagger:model NewJobsWrapper
|
||||
*/
|
||||
type NewJobsWrapper struct {
|
||||
|
||||
/* jobs
|
||||
|
||||
Required: true
|
||||
*/
|
||||
Jobs []*NewJob `json:"jobs"`
|
||||
}
|
||||
|
||||
// Validate validates this new jobs wrapper
|
||||
func (m *NewJobsWrapper) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateJobs(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *NewJobsWrapper) validateJobs(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("jobs", "body", m.Jobs); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
95
api/models/new_task.go
Normal file
95
api/models/new_task.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
/*NewTask new task
|
||||
|
||||
swagger:model NewTask
|
||||
*/
|
||||
type NewTask struct {
|
||||
|
||||
/* Number of seconds to wait before queueing the task for consumption for the first time. Must be a positive integer. Tasks with a delay start in state "delayed" and transition to "running" after delay seconds.
|
||||
*/
|
||||
Delay int32 `json:"delay,omitempty"`
|
||||
|
||||
/* Name of Docker image to use. This is optional and can be used to override the image defined at the group level.
|
||||
|
||||
Required: true
|
||||
*/
|
||||
Image *string `json:"image"`
|
||||
|
||||
/* "Number of automatic retries this task is allowed. A retry will be attempted if a task fails. Max 25. Automatic retries are performed by titan when a task reaches a failed state and has `max_retries` > 0. A retry is performed by queueing a new task with the same image id and payload. The new task's max_retries is one less than the original. The new task's `retry_of` field is set to the original Task ID. The old task's `retry_at` field is set to the new Task's ID. Titan will delay the new task for retries_delay seconds before queueing it. Cancelled or successful tasks are never automatically retried."
|
||||
|
||||
*/
|
||||
MaxRetries int32 `json:"max_retries,omitempty"`
|
||||
|
||||
/* Payload for the task. This is what you pass into each task to make it do something.
|
||||
*/
|
||||
Payload string `json:"payload,omitempty"`
|
||||
|
||||
/* Priority of the task. Higher has more priority. 3 levels from 0-2. Tasks at same priority are processed in FIFO order.
|
||||
|
||||
Required: true
|
||||
*/
|
||||
Priority *int32 `json:"priority"`
|
||||
|
||||
/* Time in seconds to wait before retrying the task. Must be a non-negative integer.
|
||||
*/
|
||||
RetriesDelay *int32 `json:"retries_delay,omitempty"`
|
||||
|
||||
/* Maximum runtime in seconds. If a consumer retrieves the
|
||||
task, but does not change it's status within timeout seconds, the task
|
||||
is considered failed, with reason timeout (Titan may allow a small
|
||||
grace period). The consumer should also kill the task after timeout
|
||||
seconds. If a consumer tries to change status after Titan has already
|
||||
timed out the task, the consumer will be ignored.
|
||||
|
||||
*/
|
||||
Timeout *int32 `json:"timeout,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this new task
|
||||
func (m *NewTask) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateImage(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validatePriority(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *NewTask) validateImage(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("image", "body", m.Image); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *NewTask) validatePriority(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("priority", "body", m.Priority); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
48
api/models/new_tasks_wrapper.go
Normal file
48
api/models/new_tasks_wrapper.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
/*NewTasksWrapper new tasks wrapper
|
||||
|
||||
swagger:model NewTasksWrapper
|
||||
*/
|
||||
type NewTasksWrapper struct {
|
||||
|
||||
/* tasks
|
||||
|
||||
Required: true
|
||||
*/
|
||||
Tasks []*NewTask `json:"tasks"`
|
||||
}
|
||||
|
||||
// Validate validates this new tasks wrapper
|
||||
func (m *NewTasksWrapper) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateTasks(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *NewTasksWrapper) validateTasks(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("tasks", "body", m.Tasks); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
57
api/models/reason.go
Normal file
57
api/models/reason.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
/*Reason Machine usable reason for job being in this state.
|
||||
Valid values for error status are `timeout | killed | bad_exit`.
|
||||
Valid values for cancelled status are `client_request`.
|
||||
For everything else, this is undefined.
|
||||
|
||||
|
||||
swagger:model Reason
|
||||
*/
|
||||
type Reason string
|
||||
|
||||
// for schema
|
||||
var reasonEnum []interface{}
|
||||
|
||||
func (m Reason) validateReasonEnum(path, location string, value Reason) error {
|
||||
if reasonEnum == nil {
|
||||
var res []Reason
|
||||
if err := json.Unmarshal([]byte(`["timeout","killed","bad_exit","client_request"]`), &res); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range res {
|
||||
reasonEnum = append(reasonEnum, v)
|
||||
}
|
||||
}
|
||||
if err := validate.Enum(path, location, value, reasonEnum); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate validates this reason
|
||||
func (m Reason) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
// value enum
|
||||
if err := m.validateReasonEnum("", "body", m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
@@ -26,6 +27,7 @@ type Route struct {
|
||||
Image string `json:"image,omitempty"`
|
||||
Memory uint64 `json:"memory,omitempty"`
|
||||
Headers http.Header `json:"headers,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Config `json:"config"`
|
||||
}
|
||||
|
||||
@@ -35,6 +37,8 @@ var (
|
||||
ErrRoutesValidationMissingAppName = errors.New("Missing route AppName")
|
||||
ErrRoutesValidationMissingPath = errors.New("Missing route Path")
|
||||
ErrRoutesValidationInvalidPath = errors.New("Invalid Path format")
|
||||
ErrRoutesValidationMissingType = errors.New("Missing route Type")
|
||||
ErrRoutesValidationInvalidType = errors.New("Invalid route Type")
|
||||
)
|
||||
|
||||
func (r *Route) Validate() error {
|
||||
@@ -60,6 +64,16 @@ func (r *Route) Validate() error {
|
||||
res = append(res, ErrRoutesValidationInvalidPath)
|
||||
}
|
||||
|
||||
if r.Type == "" {
|
||||
r.Type = "sync"
|
||||
}
|
||||
|
||||
if r.Type != "async" && r.Type != "sync" {
|
||||
res = append(res, ErrRoutesValidationInvalidType)
|
||||
}
|
||||
|
||||
fmt.Println(">>>", r.Type)
|
||||
|
||||
if len(res) > 0 {
|
||||
return apiErrors.CompositeValidationError(res...)
|
||||
}
|
||||
|
||||
22
api/models/start.go
Normal file
22
api/models/start.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package models
|
||||
|
||||
import "github.com/go-openapi/strfmt"
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
/*Start start
|
||||
|
||||
swagger:model Start
|
||||
*/
|
||||
type Start struct {
|
||||
|
||||
/* Time when task started execution. Always in UTC.
|
||||
*/
|
||||
StartedAt strfmt.DateTime `json:"started_at,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this start
|
||||
func (m *Start) Validate(formats strfmt.Registry) error {
|
||||
return nil
|
||||
}
|
||||
135
api/models/task.go
Normal file
135
api/models/task.go
Normal file
@@ -0,0 +1,135 @@
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
/*Task task
|
||||
|
||||
swagger:model Task
|
||||
*/
|
||||
type Task struct {
|
||||
NewTask
|
||||
|
||||
IDStatus
|
||||
|
||||
/* Time when task completed, whether it was successul or failed. Always in UTC.
|
||||
*/
|
||||
CompletedAt strfmt.DateTime `json:"completed_at,omitempty"`
|
||||
|
||||
/* Time when task was submitted. Always in UTC.
|
||||
|
||||
Read Only: true
|
||||
*/
|
||||
CreatedAt strfmt.DateTime `json:"created_at,omitempty"`
|
||||
|
||||
/* Env vars for the task. Comes from the ones set on the Group.
|
||||
*/
|
||||
EnvVars map[string]string `json:"env_vars,omitempty"`
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
Error string `json:"error,omitempty"`
|
||||
|
||||
/* Group this task belongs to.
|
||||
|
||||
Read Only: true
|
||||
*/
|
||||
GroupName string `json:"group_name,omitempty"`
|
||||
|
||||
/* Machine usable reason for task being in this state.
|
||||
Valid values for error status are `timeout | killed | bad_exit`.
|
||||
Valid values for cancelled status are `client_request`.
|
||||
For everything else, this is undefined.
|
||||
|
||||
*/
|
||||
Reason string `json:"reason,omitempty"`
|
||||
|
||||
/* If this field is set, then this task was retried by the task referenced in this field.
|
||||
|
||||
Read Only: true
|
||||
*/
|
||||
RetryAt string `json:"retry_at,omitempty"`
|
||||
|
||||
/* If this field is set, then this task is a retry of the ID in this field.
|
||||
|
||||
Read Only: true
|
||||
*/
|
||||
RetryOf string `json:"retry_of,omitempty"`
|
||||
|
||||
/* Time when task started execution. Always in UTC.
|
||||
*/
|
||||
StartedAt strfmt.DateTime `json:"started_at,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this task
|
||||
func (m *Task) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.NewTask.Validate(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.IDStatus.Validate(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateEnvVars(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if err := m.validateReason(formats); err != nil {
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Task) validateEnvVars(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("env_vars", "body", m.EnvVars); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var taskTypeReasonPropEnum []interface{}
|
||||
|
||||
// property enum
|
||||
func (m *Task) validateReasonEnum(path, location string, value string) error {
|
||||
if taskTypeReasonPropEnum == nil {
|
||||
var res []string
|
||||
if err := json.Unmarshal([]byte(`["timeout","killed","bad_exit","client_request"]`), &res); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range res {
|
||||
taskTypeReasonPropEnum = append(taskTypeReasonPropEnum, v)
|
||||
}
|
||||
}
|
||||
if err := validate.Enum(path, location, value, taskTypeReasonPropEnum); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Task) validateReason(formats strfmt.Registry) error {
|
||||
|
||||
// value enum
|
||||
if err := m.validateReasonEnum("reason", "body", m.Reason); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
50
api/models/task_wrapper.go
Normal file
50
api/models/task_wrapper.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
)
|
||||
|
||||
/*TaskWrapper task wrapper
|
||||
|
||||
swagger:model TaskWrapper
|
||||
*/
|
||||
type TaskWrapper struct {
|
||||
|
||||
/* task
|
||||
|
||||
Required: true
|
||||
*/
|
||||
Task *Task `json:"task"`
|
||||
}
|
||||
|
||||
// Validate validates this task wrapper
|
||||
func (m *TaskWrapper) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateTask(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *TaskWrapper) validateTask(formats strfmt.Registry) error {
|
||||
|
||||
if m.Task != nil {
|
||||
|
||||
if err := m.Task.Validate(formats); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
56
api/models/tasks_wrapper.go
Normal file
56
api/models/tasks_wrapper.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package models
|
||||
|
||||
// This file was generated by the swagger tool.
|
||||
// Editing this file might prove futile when you re-run the swagger generate command
|
||||
|
||||
import (
|
||||
strfmt "github.com/go-openapi/strfmt"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/validate"
|
||||
)
|
||||
|
||||
/*TasksWrapper tasks wrapper
|
||||
|
||||
swagger:model TasksWrapper
|
||||
*/
|
||||
type TasksWrapper struct {
|
||||
|
||||
/* Used to paginate results. If this is returned, pass it into the same query again to get more results.
|
||||
*/
|
||||
Cursor string `json:"cursor,omitempty"`
|
||||
|
||||
/* error
|
||||
*/
|
||||
Error *ErrorBody `json:"error,omitempty"`
|
||||
|
||||
/* tasks
|
||||
|
||||
Required: true
|
||||
*/
|
||||
Tasks []*Task `json:"tasks"`
|
||||
}
|
||||
|
||||
// Validate validates this tasks wrapper
|
||||
func (m *TasksWrapper) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateTasks(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *TasksWrapper) validateTasks(formats strfmt.Registry) error {
|
||||
|
||||
if err := validate.Required("tasks", "body", m.Tasks); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user