aboutsummaryrefslogtreecommitdiff
path: root/exec2/handle.go
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-11-28 12:26:41 +0100
committerAlex Auvolat <alex@adnab.me>2022-11-28 12:26:41 +0100
commit06be7dcbf6ad5a0a068d6478c98b17306af44394 (patch)
tree6f360b330b8dee925eff623c6dd61e3848c6c4d0 /exec2/handle.go
parent8977e5122acdb41e5e04f9d32338baf27fda6f49 (diff)
downloadnomad-driver-nix2-06be7dcbf6ad5a0a068d6478c98b17306af44394.tar.gz
nomad-driver-nix2-06be7dcbf6ad5a0a068d6478c98b17306af44394.zip
Import upstream exec driverupstream-exec-driver
Diffstat (limited to 'exec2/handle.go')
-rw-r--r--exec2/handle.go35
1 files changed, 17 insertions, 18 deletions
diff --git a/exec2/handle.go b/exec2/handle.go
index 6dfb976..606406b 100644
--- a/exec2/handle.go
+++ b/exec2/handle.go
@@ -1,4 +1,4 @@
-package hello
+package exec
import (
"context"
@@ -6,30 +6,26 @@ import (
"sync"
"time"
- "github.com/hashicorp/go-hclog"
- "github.com/hashicorp/go-plugin"
+ hclog "github.com/hashicorp/go-hclog"
+ plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/nomad/drivers/shared/executor"
"github.com/hashicorp/nomad/plugins/drivers"
)
-// taskHandle should store all relevant runtime information
-// such as process ID if this is a local task or other meta
-// data if this driver deals with external APIs
type taskHandle struct {
- // stateLock syncs access to all fields below
- stateLock sync.RWMutex
-
- logger hclog.Logger
exec executor.Executor
+ pid int
pluginClient *plugin.Client
- taskConfig *drivers.TaskConfig
- procState drivers.TaskState
- startedAt time.Time
- completedAt time.Time
- exitResult *drivers.ExitResult
+ logger hclog.Logger
- // TODO: add any extra relevant information about the task.
- pid int
+ // stateLock syncs access to all fields below
+ stateLock sync.RWMutex
+
+ taskConfig *drivers.TaskConfig
+ procState drivers.TaskState
+ startedAt time.Time
+ completedAt time.Time
+ exitResult *drivers.ExitResult
}
func (h *taskHandle) TaskStatus() *drivers.TaskStatus {
@@ -62,8 +58,9 @@ func (h *taskHandle) run() {
}
h.stateLock.Unlock()
- // TODO: wait for your task to complete and upate its state.
+ // Block until process exits
ps, err := h.exec.Wait(context.Background())
+
h.stateLock.Lock()
defer h.stateLock.Unlock()
@@ -77,4 +74,6 @@ func (h *taskHandle) run() {
h.exitResult.ExitCode = ps.ExitCode
h.exitResult.Signal = ps.Signal
h.completedAt = ps.Time
+
+ // TODO: detect if the task OOMed
}