Files
fn-serverless/api/runner/task/task.go
Reed Allman 6a7973e6b6 plumb all config fields into task
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.
2017-08-03 06:33:30 -07:00

86 lines
2.1 KiB
Go

package task
import (
"context"
"io"
"strings"
"time"
"github.com/fnproject/fn/api/models"
"github.com/fnproject/fn/api/runner/drivers"
"github.com/go-openapi/strfmt"
)
// TODO this whole package should be hanged, drawn & quartered
type Config struct {
ID string
AppName string
Path string
Image string
Timeout time.Duration
IdleTimeout time.Duration
Memory uint64
BaseEnv map[string]string // only app & route config vals [for hot]
Env map[string]string // includes BaseEnv
Format string
ReceivedTime time.Time
// Ready is used to await the first pull
Ready chan struct{}
Stdin io.Reader
Stdout io.Writer
Stderr io.WriteCloser // closer for flushy poo
}
// TODO Task & Config should be merged
func TaskFromConfig(cfg *Config) *models.Task {
return &models.Task{
IDStatus: models.IDStatus{ID: cfg.ID},
AppName: cfg.AppName,
Path: cfg.Path,
Image: cfg.Image,
Timeout: int32(cfg.Timeout.Seconds()),
IdleTimeout: int32(cfg.IdleTimeout.Seconds()),
Memory: cfg.Memory,
BaseEnv: cfg.BaseEnv,
EnvVars: cfg.Env,
// Format: cfg.Format, TODO plumb this
CreatedAt: strfmt.DateTime(time.Now()),
Delay: 0, // TODO not wired to users
// Payload: stdin
Priority: new(int32), // 0, TODO not wired atm to users.
}
}
func ConfigFromTask(t *models.Task) *Config {
return &Config{
ID: t.ID,
AppName: t.AppName,
Path: t.Path,
Image: t.Image,
Timeout: time.Duration(t.Timeout) * time.Second,
IdleTimeout: time.Duration(t.IdleTimeout) * time.Second,
Memory: t.Memory,
BaseEnv: t.BaseEnv,
Env: t.EnvVars,
Stdin: strings.NewReader(t.Payload),
Ready: make(chan struct{}),
}
}
// Request stores the task to be executed, It holds in itself the channel to
// return its response to its caller.
type Request struct {
Ctx context.Context
Config *Config
Response chan Response
}
// Response holds the response metainformation of a Request
type Response struct {
Result drivers.RunResult
Err error
}