From e516fc266f943da9bdb03bca3c835c5a3385bf9b Mon Sep 17 00:00:00 2001 From: Hemanth Krishna Date: Fri, 7 Oct 2022 02:03:28 +0530 Subject: [PATCH] enhancement: UpdateTask when Task is waiting for ShutdownDelay (#14775) Signed-off-by: Hemanth Krishna --- .changelog/14775.txt | 3 +++ client/allocrunner/taskrunner/task_runner.go | 4 ++++ nomad/structs/structs.go | 4 ++++ 3 files changed, 11 insertions(+) create mode 100644 .changelog/14775.txt diff --git a/.changelog/14775.txt b/.changelog/14775.txt new file mode 100644 index 000000000..631a65a18 --- /dev/null +++ b/.changelog/14775.txt @@ -0,0 +1,3 @@ +```release-note:improvement +client: Added a TaskEvent when task shutdown is waiting on shutdown_delay +``` diff --git a/client/allocrunner/taskrunner/task_runner.go b/client/allocrunner/taskrunner/task_runner.go index 664c2bf16..6f8e45c04 100644 --- a/client/allocrunner/taskrunner/task_runner.go +++ b/client/allocrunner/taskrunner/task_runner.go @@ -982,6 +982,10 @@ func (tr *TaskRunner) handleKill(resultCh <-chan *drivers.ExitResult) *drivers.E if delay := tr.Task().ShutdownDelay; delay != 0 { tr.logger.Debug("waiting before killing task", "shutdown_delay", delay) + ev := structs.NewTaskEvent(structs.TaskWaitingShuttingDownDelay). + SetDisplayMessage(fmt.Sprintf("Waiting for shutdown_delay of %s before killing the task.", delay)) + tr.UpdateState(structs.TaskStatePending, ev) + select { case result := <-resultCh: return result diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index c89bbd637..7d0da5b58 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -8159,6 +8159,10 @@ const ( // TaskClientReconnected indicates that the client running the task disconnected. TaskClientReconnected = "Reconnected" + + // TaskWaitingShuttingDownDelay indicates that the task is waiting for + // shutdown delay before being TaskKilled + TaskWaitingShuttingDownDelay = "Waiting for shutdown delay" ) // TaskEvent is an event that effects the state of a task and contains meta-data