open-nomad/plugins/drivers/task_handle.go
Nick Ethier d9628ff394 driver/raw_exec: more tests and bug fixes
added wrapper struct for plugin.ReattachConfig to better handle serialization
2018-10-16 16:53:31 -07:00

31 lines
788 B
Go

package drivers
import (
"github.com/hashicorp/nomad/plugins/base"
"github.com/ugorji/go/codec"
)
// TaskHandle is the state shared between a driver and the client.
// It is returned to the client after starting the task and used
// for recovery of tasks during a driver restart.
type TaskHandle struct {
Driver string
Config *TaskConfig
State TaskState
driverState []byte
}
func NewTaskHandle(driver string) *TaskHandle {
return &TaskHandle{Driver: driver}
}
func (h *TaskHandle) SetDriverState(v interface{}) error {
h.driverState = []byte{}
return codec.NewEncoderBytes(&h.driverState, base.MsgpackHandle).Encode(v)
}
func (h *TaskHandle) GetDriverState(v interface{}) error {
return codec.NewDecoderBytes(h.driverState, base.MsgpackHandle).Decode(v)
}