Documentation
¶
Index ¶
- Constants
- func RetryOperation(ctx context.Context, op AsyncOperation, name string, backoff time.Duration, ...) error
- func WaitForOperation(ctx context.Context, op AsyncOperation, name string, opts ...OperationOption) error
- func WaitForStatus(ctx context.Context, logger *zap.Logger, manager DaemonManager, ...) error
- type AsyncOperation
- type Daemon
- type DaemonManager
- type DaemonStatus
- type OperationOption
- type OperationOptions
- type OperationResult
Constants ¶
const ( ModeReplace = "replace" TypeSymlink = "symlink" TypeUnlink = "unlink" )
Variables ¶
This section is empty.
Functions ¶
func RetryOperation ¶
func RetryOperation(ctx context.Context, op AsyncOperation, name string, backoff time.Duration, opts ...OperationOption) error
RetryOperation retries an asynchronous operation until it succeeds or the context is cancelled. The backoff duration is the time to wait between retries. Each retry will wait for the operation to complete before retrying.
func WaitForOperation ¶
func WaitForOperation(ctx context.Context, op AsyncOperation, name string, opts ...OperationOption) error
WaitForOperation waits for an asynchronous operation to complete. If the operation returns a Failed or Timeout result, an error is returned. If the context is cancelled, an error is returned. If the operation completes with any other result (Done, Cancelled, Dependency, Skipped), nil is returned.
func WaitForStatus ¶
func WaitForStatus(ctx context.Context, logger *zap.Logger, manager DaemonManager, daemonName string, desired DaemonStatus, backoff time.Duration) error
WaitForStatus waits for the daemon to reach the desired status. It will keep checking the status of the daemon until it reaches the desired status or the context is cancelled. If you don't cancel the context, this function will keep retrying indefinitely.
Types ¶
type AsyncOperation ¶
type AsyncOperation func(ctx context.Context, daemonName string, opts ...OperationOption) error
AsyncOperation is a daemon operation that performs an action in the background.
type Daemon ¶
type Daemon interface { // Configure configures the daemon. Configure() error // EnsureRunning ensures that the daemon is running. // If the daemon is not running, it will be started. // If the daemon is already running, and has been re-configured, it will be restarted. EnsureRunning(ctx context.Context) error // PostLaunch runs any additional step that needs to occur after the service // daemon as been started PostLaunch() error // Stop stops the daemon // If the daemon is already stopped, this will be a no-op Stop() error // Name returns the name of the daemon. Name() string }
type DaemonManager ¶
type DaemonManager interface { // StartDaemon starts the daemon with the given name. // If the daemon is already running, this is a no-op. StartDaemon(name string) error // StopDaemon stops the daemon with the given name. // If the daemon is not running, this is a no-op. StopDaemon(name string) error // RestartDaemon restarts the daemon with the given name. // If the daemon is not running, it will be started. RestartDaemon(ctx context.Context, name string, opts ...OperationOption) error // GetDaemonStatus returns the status of the daemon with the given name. GetDaemonStatus(name string) (DaemonStatus, error) // EnableDaemon enables the daemon with the given name. // If the daemon is already enabled, this is a no-op. EnableDaemon(name string) error // DisableDaemon disables the daemon with the given name. // If the daemon is not enabled, this is a no-op. DisableDaemon(name string) error // DaemonReload will reload all the daemons DaemonReload() error // Close cleans up any underlying resources used by the daemon manager. Close() }
func NewDaemonManager ¶
func NewDaemonManager() (DaemonManager, error)
type DaemonStatus ¶
type DaemonStatus string
const ( DaemonStatusRunning DaemonStatus = "running" DaemonStatusStopped DaemonStatus = "stopped" DaemonStatusUnknown DaemonStatus = "unknown" )
type OperationOption ¶
type OperationOption func(*OperationOptions)
OperationOption is a function that modifies the OperationOptions.
type OperationOptions ¶
type OperationOptions struct { Result chan<- OperationResult Mode string }
OperationOptions allows to customize the behavior of a daemon operation.
func (*OperationOptions) ApplyAll ¶
func (o *OperationOptions) ApplyAll(in *OperationOptions)
ApplyAll allows OperationOptions to be used as an OperationOption.
type OperationResult ¶
type OperationResult string
OperationResult represents the result of a daemon operation.
const ( // Done indicates successful execution of a job. Done OperationResult = "done" // Canceled indicates that a job has been canceled before it finished execution. Canceled OperationResult = "canceled" // Timeout indicates that the job timeout was reached. Timeout OperationResult = "timeout" // Failed indicates that the job failed. Failed OperationResult = "failed" // Dependency indicates that a job this job has been depending on failed and the job hence has been removed too. Dependency OperationResult = "dependency" // Skipped indicates that a job was skipped because it didn't apply to the units current state. Skipped OperationResult = "skipped" )