Skip to content

Commit

Permalink
address code review: change interface method name to IsRunning
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Dec 15, 2020
1 parent f03c7b5 commit 2da0b1f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions client/allocrunner/taskrunner/interfaces/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ type TaskLifecycle interface {
// Kill a task permanently.
Kill(ctx context.Context, event *structs.TaskEvent) error

// HasHandle returns true if the task runner has a handle to the task
// IsRunning returns true if the task runner has a handle to the task
// driver, which is useful for distinguishing restored tasks during
// prestart hooks. Note: prestart should be idempotent whenever possible
// to handle restored tasks safely; use this as an escape hatch.
HasHandle() bool
// prestart hooks. But note that the driver handle could go away after you
// check this, so callers should make sure they're handling that case
// safely. Ideally prestart hooks should be idempotnent whenever possible
// to handle restored tasks; use this as an escape hatch.
IsRunning() bool
}
2 changes: 1 addition & 1 deletion client/allocrunner/taskrunner/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ WAIT:

// if there's a driver handle then the task is already running and
// that changes how we want to behave on first render
if dirty && tm.config.Lifecycle.HasHandle() {
if dirty && tm.config.Lifecycle.IsRunning() {
handledRenders := make(map[string]time.Time, len(tm.config.Templates))
tm.onTemplateRendered(handledRenders, time.Time{})
}
Expand Down
2 changes: 1 addition & 1 deletion client/allocrunner/taskrunner/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (m *MockTaskHooks) Kill(ctx context.Context, event *structs.TaskEvent) erro
return nil
}

func (m *MockTaskHooks) HasHandle() bool {
func (m *MockTaskHooks) IsRunning() bool {
return m.hasHandle
}

Expand Down

0 comments on commit 2da0b1f

Please sign in to comment.