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.
This commit is contained in:
Reed Allman
2017-08-03 04:30:16 -07:00
parent 7758e4a76a
commit 6a7973e6b6
15 changed files with 115 additions and 208 deletions

View File

@@ -27,22 +27,23 @@ func (p *HTTPProtocol) IsStreamable() bool {
return true
}
func (p *HTTPProtocol) Dispatch(ctx context.Context, t task.Request) error {
func (p *HTTPProtocol) Dispatch(ctx context.Context, cfg *task.Config) error {
var retErr error
done := make(chan struct{})
go func() {
// TODO not okay. plumb content-length from req into cfg..
var body bytes.Buffer
io.Copy(&body, t.Config.Stdin)
io.Copy(&body, cfg.Stdin)
req, err := http.NewRequest("GET", "/", &body)
if err != nil {
retErr = err
return
}
for k, v := range t.Config.Env {
for k, v := range cfg.Env {
req.Header.Set(k, v)
}
req.Header.Set("Content-Length", fmt.Sprint(body.Len()))
req.Header.Set("Task-ID", t.Config.ID)
req.Header.Set("Task-ID", cfg.ID)
raw, err := httputil.DumpRequest(req, true)
if err != nil {
retErr = err
@@ -56,11 +57,11 @@ func (p *HTTPProtocol) Dispatch(ctx context.Context, t task.Request) error {
return
}
io.Copy(t.Config.Stdout, res.Body)
io.Copy(cfg.Stdout, res.Body)
done <- struct{}{}
}()
timeout := time.After(t.Config.Timeout)
timeout := time.After(cfg.Timeout)
select {
case <-ctx.Done():