mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* get rid of old format stuff, utils usage, fix up for fdk2.0 interface * pure agent format removal, TODO remove format field, fix up all tests * shitter's clogged * fix agent tests * start rolling through server tests * tests compile, some failures * remove json / content type detection on invoke/httptrigger, fix up tests * remove hello, fixup system tests the fucking status checker test just hangs and it's testing that it doesn't work so the test passes but the test doesn't pass fuck life it's not worth it * fix migration * meh * make dbhelper shut up about dbhelpers not being used * move fail status at least into main thread, jfc * fix status call to have FN_LISTENER also turns off the stdout/stderr blocking between calls, because it's impossible to debug without that (without syslog), now that stdout and stderr go to the same place (either to host stderr or nowhere) and isn't used for function output this shouldn't be a big fuss really * remove stdin * cleanup/remind: fixed bug where watcher would leak if container dies first * silence system-test logs until fail, fix datastore tests postgres does weird things with constraints when renaming tables, took the easy way out system-tests were loud as fuck and made you download a circleci text file of the logs, made them only yell when they goof * fix fdk-go dep for test image. fun * fix swagger and remove test about format * update all the gopkg files * add back FN_FORMAT for fdks that assert things. pfft * add useful error for functions that exit this error is really confounding because containers can exit for all manner of reason, we're just guessing that this is the most likely cause for now, and this error message should very likely change or be removed from the client path anyway (context.Canceled wasn't all that useful either, but anyway, I'd been hunting for this... so found it). added a test to avoid being publicly shamed for 1 line commits (beware...).
158 lines
5.6 KiB
Go
158 lines
5.6 KiB
Go
package models
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/fnproject/fn/api/agent/drivers"
|
|
"github.com/fnproject/fn/api/common"
|
|
)
|
|
|
|
const (
|
|
// TypeNone ...
|
|
TypeNone = ""
|
|
// TypeSync ...
|
|
TypeSync = "sync"
|
|
// TypeAsync ...
|
|
TypeAsync = "async"
|
|
)
|
|
|
|
var possibleStatuses = [...]string{"delayed", "queued", "running", "success", "error", "cancelled"}
|
|
|
|
// Call is a representation of a specific invocation of a fn.
|
|
type Call struct {
|
|
// Unique identifier representing a specific call.
|
|
ID string `json:"id" db:"id"`
|
|
|
|
// NOTE: this is stale, retries are not implemented atm, but this is nice, so leaving
|
|
// States and valid transitions.
|
|
//
|
|
// +---------+
|
|
// +---------> delayed <----------------+
|
|
// +----+----+ |
|
|
// | |
|
|
// | |
|
|
// +----v----+ |
|
|
// +---------> queued <----------------+
|
|
// +----+----+ *
|
|
// | *
|
|
// | retry * creates new call
|
|
// +----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.
|
|
Status string `json:"status" db:"status"`
|
|
|
|
// Name of Docker image to use.
|
|
Image string `json:"image,omitempty" db:"-"`
|
|
|
|
// Number of seconds to wait before queueing the call for consumption for the
|
|
// first time. Must be a positive integer. Calls with a delay start in state
|
|
// "delayed" and transition to "running" after delay seconds.
|
|
Delay int32 `json:"delay,omitempty" db:"-"`
|
|
|
|
// Type indicates whether a task is to be run synchronously or asynchronously.
|
|
Type string `json:"type,omitempty" db:"-"`
|
|
|
|
// Payload for the call. This is only used by async calls, to store their input.
|
|
// TODO should we copy it into here too for debugging sync?
|
|
Payload string `json:"payload,omitempty" db:"-"`
|
|
|
|
// Full request url that spawned this invocation.
|
|
URL string `json:"url,omitempty" db:"-"`
|
|
|
|
// Method of the http request used to make this call.
|
|
Method string `json:"method,omitempty" db:"-"`
|
|
|
|
// Priority of the call. Higher has more priority. 3 levels from 0-2. Calls
|
|
// at same priority are processed in FIFO order.
|
|
Priority *int32 `json:"priority,omitempty" db:"-"`
|
|
|
|
// Maximum runtime in seconds.
|
|
Timeout int32 `json:"timeout,omitempty" db:"-"`
|
|
|
|
// Hot function idle timeout in seconds before termination.
|
|
IdleTimeout int32 `json:"idle_timeout,omitempty" db:"-"`
|
|
|
|
// Tmpfs size in megabytes.
|
|
TmpFsSize uint32 `json:"tmpfs_size,omitempty" db:"-"`
|
|
|
|
// Memory is the amount of RAM this call is allocated.
|
|
Memory uint64 `json:"memory,omitempty" db:"-"`
|
|
|
|
// CPU as in MilliCPUs where each CPU core is split into 1000 units, specified either
|
|
// *) milliCPUs as "100m" which is 1/10 of a CPU or
|
|
// *) as floating point number "0.1" which is 1/10 of a CPU
|
|
CPUs MilliCPUs `json:"cpus,omitempty" db:"-"`
|
|
|
|
// Config is the set of configuration variables for the call
|
|
Config Config `json:"config,omitempty" db:"-"`
|
|
|
|
// Annotations is the set of annotations for the app/fn of the call.
|
|
Annotations Annotations `json:"annotations,omitempty" db:"-"`
|
|
|
|
// Headers are headers from the request that created this call
|
|
Headers http.Header `json:"headers,omitempty" db:"-"`
|
|
|
|
// SyslogURL is a syslog URL to send all logs to.
|
|
SyslogURL string `json:"syslog_url,omitempty" db:"-"`
|
|
|
|
// Time when call completed, whether it was successul or failed. Always in UTC.
|
|
CompletedAt common.DateTime `json:"completed_at,omitempty" db:"completed_at"`
|
|
|
|
// Time when call was submitted. Always in UTC.
|
|
CreatedAt common.DateTime `json:"created_at,omitempty" db:"created_at"`
|
|
|
|
// Time when call started execution. Always in UTC.
|
|
StartedAt common.DateTime `json:"started_at,omitempty" db:"started_at"`
|
|
|
|
// Stats is a list of metrics from this call's execution, possibly empty.
|
|
Stats drivers.Stats `json:"stats,omitempty" db:"stats"`
|
|
|
|
// Error is the reason why the call failed, it is only non-empty if
|
|
// status is equal to "error".
|
|
Error string `json:"error,omitempty" db:"error"`
|
|
|
|
// App this call belongs to.
|
|
AppID string `json:"app_id" db:"app_id"`
|
|
|
|
// Name of the app.
|
|
AppName string `json:"app_name" db:"app_name"`
|
|
|
|
// Trigger this call belongs to.
|
|
TriggerID string `json:"trigger_id" db:"trigger_id"`
|
|
|
|
// Fn this call belongs to.
|
|
FnID string `json:"fn_id" db:"fn_id"`
|
|
}
|
|
|
|
type CallFilter struct {
|
|
FnID string //match
|
|
FromTime common.DateTime
|
|
ToTime common.DateTime
|
|
Cursor string
|
|
PerPage int
|
|
}
|
|
|
|
type CallList struct {
|
|
NextCursor string `json:"next_cursor,omitempty"`
|
|
Items []*Call `json:"items"`
|
|
}
|