hookstate

package
v0.0.0-...-677ed08 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2016 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package hookstate implements the manager and state aspects responsible for the running of hooks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HookTask

func HookTask(s *state.State, taskSummary, snapName string, revision snap.Revision, hookName string, initialContext map[string]interface{}) *state.Task

HookTask returns a task that will run the specified hook. Note that the initial context must properly marshal and unmarshal with encoding/json.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context represents the context under which a given hook is running.

func NewContext

func NewContext(task *state.Task, setup *HookSetup, handler Handler) (*Context, error)

NewContext returns a new Context.

func (*Context) Cache

func (c *Context) Cache(key, value interface{})

Cache associates value with key. The cached value is not persisted. Note that the context needs to be locked/unlocked by the caller.

func (*Context) Cached

func (c *Context) Cached(key interface{}) interface{}

Cached returns the cached value associated with the provided key. It returns nil if there is no entry for key. Note that the context needs to be locked and unlocked by the caller.

func (*Context) Done

func (c *Context) Done() error

Done is called to notify the context that its hook has exited successfully. It will call all of the functions added in OnDone (even if one of them returns an error) and will return the first error encountered. Note that the context needs to be locked/unlocked by the caller.

func (*Context) Get

func (c *Context) Get(key string, value interface{}) error

Get unmarshals the stored value associated with the provided key into the value parameter. Note that the context needs to be locked/unlocked by the caller.

func (*Context) Handler

func (c *Context) Handler() Handler

Handler returns the handler for this context

func (*Context) HookName

func (c *Context) HookName() string

HookName returns the name of the hook in this context.

func (*Context) ID

func (c *Context) ID() string

ID returns the ID of the context.

func (*Context) Lock

func (c *Context) Lock()

Lock acquires the lock for this context (required for Set/Get, Cache/Cached), and OnDone/Done).

func (*Context) OnDone

func (c *Context) OnDone(f func() error)

OnDone requests the provided function to be run once the context knows it's complete. This can be called multiple times; each function will be called in the order in which they were added. Note that the context needs to be locked and unlocked by the caller.

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set associates value with key. The provided value must properly marshal and unmarshal with encoding/json. Note that the context needs to be locked and unlocked by the caller.

func (*Context) SnapName

func (c *Context) SnapName() string

SnapName returns the name of the snap containing the hook.

func (*Context) SnapRevision

func (c *Context) SnapRevision() snap.Revision

SnapRevision returns the revision of the snap containing the hook.

func (*Context) State

func (c *Context) State() *state.State

State returns the state contained within the context

func (*Context) Unlock

func (c *Context) Unlock()

Unlock releases the lock for this context.

type Handler

type Handler interface {
	// Before is called right before the hook is to be run.
	Before() error

	// Done is called right after the hook has finished successfully.
	Done() error

	// Error is called if the hook encounters an error while running.
	Error(err error) error
}

Handler is the interface a client must satify to handle hooks.

type HandlerGenerator

type HandlerGenerator func(*Context) Handler

HandlerGenerator is the function signature required to register for hooks.

type HookManager

type HookManager struct {
	// contains filtered or unexported fields
}

HookManager is responsible for the maintenance of hooks in the system state. It runs hooks when they're requested, assuming they're present in the given snap. Otherwise they're skipped with no error.

func Manager

func Manager(s *state.State) (*HookManager, error)

Manager returns a new HookManager.

func (*HookManager) Context

func (m *HookManager) Context(contextID string) (*Context, error)

Context obtains the context for the given context ID.

func (*HookManager) Ensure

func (m *HookManager) Ensure() error

Ensure implements StateManager.Ensure.

func (*HookManager) Register

func (m *HookManager) Register(pattern *regexp.Regexp, generator HandlerGenerator)

Register requests that a given handler generator be called when a matching hook is run, and the handler be used for the hook.

Specifically, if a matching hook is about to be run, the handler's Before() method will be called. After the hook has completed running, either the handler's Done() method or its Error() method will be called, depending on the outcome.

func (*HookManager) Stop

func (m *HookManager) Stop()

Stop implements StateManager.Stop.

func (*HookManager) Wait

func (m *HookManager) Wait()

Wait implements StateManager.Wait.

type HookSetup

type HookSetup struct {
	Snap     string        `json:"snap"`
	Revision snap.Revision `json:"revision"`
	Hook     string        `json:"hook"`
}

HookSetup is a reference to a hook within a specific snap.

Directories

Path Synopsis
Package ctlcmd contains the various snapctl subcommands.
Package ctlcmd contains the various snapctl subcommands.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL