github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/client/allocrunner/interfaces/runner_lifecycle.go (about)

     1  package interfaces
     2  
     3  import (
     4  	"github.com/hashicorp/nomad/nomad/structs"
     5  )
     6  
     7  // RunnnerHook is a lifecycle hook into the life cycle of an allocation runner.
     8  type RunnerHook interface {
     9  	Name() string
    10  }
    11  
    12  // RunnerPrerunHooks are executed before calling TaskRunner.Run for
    13  // non-terminal allocations. Terminal allocations do *not* call prerun.
    14  type RunnerPrerunHook interface {
    15  	RunnerHook
    16  	Prerun() error
    17  }
    18  
    19  // RunnerPreKillHooks are executed inside of KillTasks before
    20  // iterating and killing each task. It will run before the Leader
    21  // task is killed.
    22  type RunnerPreKillHook interface {
    23  	RunnerHook
    24  
    25  	PreKill()
    26  }
    27  
    28  // RunnerPostrunHooks are executed after calling TaskRunner.Run, even for
    29  // terminal allocations. Therefore Postrun hooks must be safe to call without
    30  // first calling Prerun hooks.
    31  type RunnerPostrunHook interface {
    32  	RunnerHook
    33  	Postrun() error
    34  }
    35  
    36  // RunnerDestroyHooks are executed after AllocRunner.Run has exited and must
    37  // make a best effort cleanup allocation resources. Destroy hooks must be safe
    38  // to call without first calling Prerun.
    39  type RunnerDestroyHook interface {
    40  	RunnerHook
    41  	Destroy() error
    42  }
    43  
    44  // RunnerUpdateHooks are executed when an allocation update is received from
    45  // the server. Update is called concurrently with AllocRunner execution and
    46  // therefore must be safe for concurrent access with other hook methods. Calls
    47  // to Update are serialized so allocaiton updates will always be processed in
    48  // order.
    49  type RunnerUpdateHook interface {
    50  	RunnerHook
    51  	Update(*RunnerUpdateRequest) error
    52  }
    53  
    54  type RunnerUpdateRequest struct {
    55  	Alloc *structs.Allocation
    56  }
    57  
    58  // ShutdownHook may be implemented by AllocRunner or TaskRunner hooks and will
    59  // be called when the agent process is being shutdown gracefully.
    60  type ShutdownHook interface {
    61  	RunnerHook
    62  
    63  	Shutdown()
    64  }