mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
docker: sync access to exit result within a handle
This commit is contained in:
@@ -83,8 +83,7 @@ type Driver struct {
|
||||
// coordinator is what tracks multiple image pulls against the same docker image
|
||||
coordinator *dockerCoordinator
|
||||
|
||||
// logger will log to the plugin output which is usually an 'executor.out'
|
||||
// file located in the root of the TaskDir
|
||||
// logger will log to the Nomad agent
|
||||
logger hclog.Logger
|
||||
}
|
||||
|
||||
@@ -990,7 +989,7 @@ func (d *Driver) handleWait(ctx context.Context, ch chan *drivers.ExitResult, h
|
||||
defer close(ch)
|
||||
select {
|
||||
case <-h.waitCh:
|
||||
ch <- h.exitResult
|
||||
ch <- h.ExitResult()
|
||||
case <-ctx.Done():
|
||||
ch <- &drivers.ExitResult{
|
||||
Err: ctx.Err(),
|
||||
@@ -1080,7 +1079,7 @@ func (d *Driver) InspectTask(taskID string) (*drivers.TaskStatus, error) {
|
||||
"container_id": container.ID,
|
||||
},
|
||||
NetworkOverride: h.net,
|
||||
ExitResult: h.exitResult,
|
||||
ExitResult: h.ExitResult(),
|
||||
}
|
||||
|
||||
status.State = drivers.TaskStateUnknown
|
||||
|
||||
@@ -38,7 +38,14 @@ type taskHandle struct {
|
||||
net *structs.DriverNetwork
|
||||
imageID string
|
||||
|
||||
exitResult *drivers.ExitResult
|
||||
exitResult *drivers.ExitResult
|
||||
exitResultLock sync.Mutex
|
||||
}
|
||||
|
||||
func (h *taskHandle) ExitResult() *drivers.ExitResult {
|
||||
h.exitResultLock.Lock()
|
||||
defer h.exitResultLock.Unlock()
|
||||
return h.exitResult.Copy()
|
||||
}
|
||||
|
||||
type taskHandleState struct {
|
||||
@@ -202,12 +209,14 @@ func (h *taskHandle) run() {
|
||||
}
|
||||
|
||||
// Set the result
|
||||
h.exitResultLock.Lock()
|
||||
h.exitResult = &drivers.ExitResult{
|
||||
ExitCode: exitCode,
|
||||
Signal: 0,
|
||||
OOMKilled: oom,
|
||||
Err: werr,
|
||||
}
|
||||
h.exitResultLock.Unlock()
|
||||
close(h.waitCh)
|
||||
}
|
||||
|
||||
|
||||
@@ -249,6 +249,12 @@ func (r *ExitResult) Successful() bool {
|
||||
return r.ExitCode == 0 && r.Signal == 0 && r.Err == nil
|
||||
}
|
||||
|
||||
func (r *ExitResult) Copy() *ExitResult {
|
||||
res := new(ExitResult)
|
||||
*res = *r
|
||||
return res
|
||||
}
|
||||
|
||||
type TaskStatus struct {
|
||||
ID string
|
||||
Name string
|
||||
|
||||
Reference in New Issue
Block a user