github.com/bigcommerce/nomad@v0.9.3-bc/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  // RunnerPostrunHooks are executed after calling TaskRunner.Run, even for
    20  // terminal allocations. Therefore Postrun hooks must be safe to call without
    21  // first calling Prerun hooks.
    22  type RunnerPostrunHook interface {
    23  	RunnerHook
    24  	Postrun() error
    25  }
    26  
    27  // RunnerDestroyHooks are executed after AllocRunner.Run has exited and must
    28  // make a best effort cleanup allocation resources. Destroy hooks must be safe
    29  // to call without first calling Prerun.
    30  type RunnerDestroyHook interface {
    31  	RunnerHook
    32  	Destroy() error
    33  }
    34  
    35  // RunnerUpdateHooks are executed when an allocation update is received from
    36  // the server. Update is called concurrently with AllocRunner execution and
    37  // therefore must be safe for concurrent access with other hook methods. Calls
    38  // to Update are serialized so allocaiton updates will always be processed in
    39  // order.
    40  type RunnerUpdateHook interface {
    41  	RunnerHook
    42  	Update(*RunnerUpdateRequest) error
    43  }
    44  
    45  type RunnerUpdateRequest struct {
    46  	Alloc *structs.Allocation
    47  }
    48  
    49  // ShutdownHook may be implemented by AllocRunner or TaskRunner hooks and will
    50  // be called when the agent process is being shutdown gracefully.
    51  type ShutdownHook interface {
    52  	RunnerHook
    53  
    54  	Shutdown()
    55  }