github.com/bigcommerce/nomad@v0.9.3-bc/drivers/rawexec/driver_pre09.go (about) 1 package rawexec 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/hashicorp/nomad/client/state" 8 "github.com/hashicorp/nomad/drivers/shared/executor" 9 "github.com/hashicorp/nomad/plugins/drivers" 10 pstructs "github.com/hashicorp/nomad/plugins/shared/structs" 11 ) 12 13 func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error { 14 handle, err := state.UnmarshalPre09HandleID(h.DriverState) 15 if err != nil { 16 return fmt.Errorf("failed to decode pre09 driver handle: %v", err) 17 } 18 19 reattach, err := pstructs.ReattachConfigToGoPlugin(handle.ReattachConfig()) 20 if err != nil { 21 return fmt.Errorf("failed to decode reattach config from pre09 handle: %v", err) 22 } 23 24 exec, pluginClient, err := executor.ReattachToPre09Executor(reattach, 25 d.logger.With("task_name", h.Config.Name, "alloc_id", h.Config.AllocID)) 26 if err != nil { 27 d.logger.Error("failed to reattach to executor", "error", err, "task_name", h.Config.Name) 28 return fmt.Errorf("failed to reattach to executor: %v", err) 29 } 30 31 th := &taskHandle{ 32 exec: exec, 33 pid: reattach.Pid, 34 pluginClient: pluginClient, 35 taskConfig: h.Config, 36 procState: drivers.TaskStateRunning, 37 startedAt: time.Now(), 38 exitResult: &drivers.ExitResult{}, 39 logger: d.logger, 40 doneCh: make(chan struct{}), 41 } 42 43 d.tasks.Set(h.Config.ID, th) 44 45 go th.run() 46 return nil 47 }