run

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: May 1, 2022 License: GPL-3.0 Imports: 22 Imported by: 0

README

Run Package

Since the run package is the most important package in Act we going to give a high level overview of its functionality here.

TBD

Documentation

Index

Constants

View Source
const (
	ExecStateStopped string = "stopped"
	ExecStateRunning        = "running"
)

############################################################ Types ############################################################ *

  • Execution state.
View Source
const ActCallIdSeparator = "."

*

  • In s subact chain we separate each act name by this separator
  • like when we run `act run foo.bar`. In this case `bar` is a
  • subact of the act `foo` and the whole act is uniquely identified
  • by the name `foo.bar`.
View Source
const ActDataDirName = ".actdt"

*

  • This is the name of the directory where we going to hold
  • all info for running acts.
View Source
const EnvFileName = "env"

*

  • This is the name of dotenv var file we use to share variables
  • between act/command execution.
View Source
const InfoFileName = "info.json"

*

  • This is the file name we going to use when saving the info
  • struct back to file system.

Variables

This section is empty.

Functions

func CmdExec

func CmdExec(cmd *actfile.Cmd, ctx *ActRunCtx, wg *sync.WaitGroup)

*

  • This function going to execute a command.

func Exec

func Exec(args []string)

############################################################ Exported Functions ############################################################ *

  • This function to execute run command.

func Finish added in v1.4.0

func Finish()

*

  • This function going to cleanup everything for this command on exit.

func StageCmdsExec added in v1.3.0

func StageCmdsExec(stage *actfile.ActExecStage, ctx *ActRunCtx)

*

  • This function going to execute a stage.

func Stop added in v1.4.0

func Stop()

*

  • This function going to stop execution of current running
  • commands.

Types

type ActRunCtx

type ActRunCtx struct {
	/**
	 * Reference to global run context.
	 */
	RunCtx *RunCtx

	/**
	 * Actfile where we found this act.
	 */
	ActFile *actfile.ActFile

	/**
	 * The act to run.
	 */
	Act *actfile.Act

	/**
	 * Prev context in the chain.
	 */
	PrevCtx *ActRunCtx

	/**
	 * This is the call id for the act.
	 */
	CallId string

	/**
	 * Indicates which stage is currently running.
	 */
	CurrentStage *actfile.ActExecStage

	/**
	 * List of cli flag values passed by the user.
	 */
	FlagVals map[string]string

	/**
	 * Cli arguments after extracting flags.
	 */
	Args []string

	/**
	 * Set of variables passed from parent acts.
	 */
	ParentVars map[string]string

	/**
	 * Act runtime vars.
	 */
	ActVars map[string]string

	/**
	 * Set of variables scoped to act execution.
	 */
	Vars map[string]string
}

*

  • This is the context to run an act.

func FindActCtx

func FindActCtx(
	actNames []string,
	actFile *actfile.ActFile,
	prevCtx *ActRunCtx,
	runCtx *RunCtx,
) (*ActRunCtx, error)

*

  • This function going to find an act to run based on the call id
  • user provided.

func (*ActRunCtx) Exec

func (ctx *ActRunCtx) Exec()

*

  • This function going to execute an act.

func (*ActRunCtx) ExecBeforeAll

func (ctx *ActRunCtx) ExecBeforeAll()

*

  • This function going to run all before acts not already
  • executed for the whole act run context chain.

func (*ActRunCtx) FinalStageExec added in v1.4.0

func (ctx *ActRunCtx) FinalStageExec()

*

  • This function going to run teardown commands of currently
  • running act upon exit. *
  • @TODO: We need to run teardown cmds of all running acts.

func (*ActRunCtx) GetLocalVars added in v1.4.0

func (ctx *ActRunCtx) GetLocalVars() map[string]string

*

  • This function get local variables.

func (*ActRunCtx) MergeVars

func (ctx *ActRunCtx) MergeVars() map[string]string

*

  • This function going to merge all variables altogether.

func (*ActRunCtx) Print

func (ctx *ActRunCtx) Print()

*

  • This is an utilitary function that going to print the content
  • of this act run context. We get the whole act run context stack
  • so we can print the whole chain from the first one.

func (*ActRunCtx) Stack

func (ctx *ActRunCtx) Stack() []*ActRunCtx

*

  • This function going to get the whole act run context stack
  • starting from this act run context. Act contexts are linked
  • together (linked list) but it could happen that multiple
  • act run context has the same previous context in this liked
  • list (this happen when we run commands in parallel that call
  • other acts). This way is useful to be able to get the whole
  • stack of act contexts starting from any node in this linked
  • list (for printing for example).

func (*ActRunCtx) VarsToEnvVars

func (ctx *ActRunCtx) VarsToEnvVars(vars map[string]string) []string

*

  • This function convert vars to env vars.

type Info

type Info struct {
	/**
	 * Which running act going to receive an unique short hash
	 * id which going to be used to name the data folder for
	 * this act in the act data dir.
	 */
	Id string

	/**
	 * If this act was created from another act process then we
	 * going to store parent act id here. We do this because we
	 * need to update parent when the state of this act change.
	 */
	ParentActId string

	/**
	 * Name is a human friendly id assigned by the user when
	 * running the act. User can then use this name to stop
	 * o get logs for the act.
	 */
	NameId string

	/**
	 * This is the process group id of this act process.
	 */
	Pgid int

	/**
	 * This is the process id.
	 */
	Pid int

	/**
	 * This is the list of all command process group ids created
	 * by this act process. When we are running a sync act then
	 * at any given time this array going to have one and only one
	 * pgid (the pgid of currently running command). When running a
	 * parallel act then usually this array going to contain the
	 * pgids of all commands running in parallel.
	 */
	CmdPgids []int

	/**
	 * This is a list of ids of all act detached processes created
	 * by this act process.
	 */
	ChildActIds []string

	/**
	 * Flag to indicate we are killing the process.
	 */
	IsKilling bool
	// contains filtered or unexported fields
}

*

  • This struct going to hold run context info that going to
  • be stored to a file describing a running act.

func GetAllInfo

func GetAllInfo() []*Info

*

  • This function going to get all run info.

func GetInfo

func GetInfo(name string) *Info

*

  • This function get info for a specific act by its name
  • as associated by the user.

func GetInfoCallStack

func GetInfoCallStack(id string) []*Info

############################################################ Exported Functions ############################################################ *

  • This function get call stack from an act id.

func (*Info) AddChildActId

func (info *Info) AddChildActId(id string)

############################################################ Info Struct Functions ############################################################ *

  • This function going to add a new child act run id to info
  • and then save info back to file system.

func (*Info) AddCmdPgid

func (info *Info) AddCmdPgid(pgid int)

*

  • This function going to add a new Pgid to info and then save
  • info back to file system.

func (*Info) GetDataDirPath

func (info *Info) GetDataDirPath() string

*

  • This function get data dir for this run info.

func (*Info) GetEnvVarsFilePath

func (info *Info) GetEnvVarsFilePath() string

*

  • This function get env vars file path for this run info.

func (*Info) GetLogFilePath

func (info *Info) GetLogFilePath() string

*

  • This function get the log file path for this run info.

func (*Info) GetNameIdOrId

func (info *Info) GetNameIdOrId() string

*

  • This function get name id if present or id otherwise.

func (*Info) Kill

func (info *Info) Kill()

*

  • This function going to quit a running process associated
  • with this specific info.

func (*Info) KillChildActs added in v1.4.0

func (info *Info) KillChildActs()

*

  • This function going to kill only the running child detached acts.

func (*Info) KillChildCmds added in v1.4.0

func (info *Info) KillChildCmds()

*

  • This function going to kill only the running child commands.

func (*Info) KillChildren added in v1.4.0

func (info *Info) KillChildren()

*

  • This function going to kill all children processes associated
  • with this info.

func (*Info) RmChildActId

func (info *Info) RmChildActId(id string)

*

  • This function removes a child act run id from info and
  • then save the info back to file system.

func (*Info) RmCmdPgid

func (info *Info) RmCmdPgid(pgid int)

*

  • This function removes a pgid from info and then save the info
  • back to file system.

func (*Info) RmDataDir

func (info *Info) RmDataDir()

*

  • This function going to remove run info directory.

func (*Info) Save

func (info *Info) Save()

*

  • This function going to save info to a file in the data
  • directory.

func (*Info) SetIsKilling

func (info *Info) SetIsKilling()

*

  • This function going to set IsKilling flag.

type LogWriter

type LogWriter struct {
	Detached     bool
	LogToConsole bool
	// contains filtered or unexported fields
}

*

  • This is the main struct which implements io.Writer interface
  • to be used as stdout/stderr for commands.

func NewLogWriter

func NewLogWriter(ctx *ActRunCtx) *LogWriter

*

  • This function going to create a new log writer.

func (*LogWriter) Close

func (l *LogWriter) Close() error

*

  • This finction close the writer.

func (*LogWriter) Flush

func (l *LogWriter) Flush() error

*

  • Flush all buffered bytes to screen/file.

func (*LogWriter) OutputLines

func (l *LogWriter) OutputLines() (err error)

*

  • This function going to output line by line from buffer.

func (LogWriter) Write

func (l LogWriter) Write(p []byte) (n int, err error)

*

  • This function implements io.Writer interface.

type RunCtx

type RunCtx struct {
	/**
	 * Cli arguments passed by the user.
	 */
	Args []string

	/**
	 * This is the act ctx we going to execute.
	 */
	ActCtx *ActRunCtx

	/**
	 * This is the root actfile.
	 */
	ActFile *actfile.ActFile

	/**
	 * This is a set indicating which actfiles were already loaded.
	 */
	LoadedActFiles map[string]bool

	/**
	 * This are global variables to be used by all acts in the stack.
	 */
	Vars map[string]string

	/**
	 * Set of variables loaded from file.
	 */
	EnvFileVars map[string]string

	/**
	 * Act runtime variables.
	 */
	ActVars map[string]string

	/**
	 * This stack going to hold all acts run contexts we have
	 * active so far.
	 */
	ActCtxCallStack []*ActRunCtx

	/**
	 * Run context info as stored in act data dir.
	 */
	Info *Info

	/**
	 * Flag indicating if we are running the process as a
	 * daemon in the background.
	 */
	IsDaemon bool

	/**
	 * Flag indicating the state of the execution.
	 */
	State string

	/**
	 * Flag indicating we are finishing the execution.
	 */
	IsFinishing bool

	/**
	 * Log mode.
	 */
	Log string

	/**
	 * Flag indicating we should supress all logs.
	 */
	Quiet bool
}

*

  • This run context going to hold all global info we need to run
  • an act.

func (*RunCtx) Print

func (ctx *RunCtx) Print()

*

  • This function going to print all info about this run context.

Jump to

Keyboard shortcuts

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