Documentation ¶
Overview ¶
Package run starts and tracks running Encore applications.
Index ¶
- Constants
- func GenID() string
- func IgnoreEvents(events []watcher.Event) bool
- type AsyncBuildJobs
- type EventListener
- type ExecScriptParams
- type Manager
- func (mgr *Manager) AddListener(ln EventListener)
- func (mgr *Manager) Check(ctx context.Context, appRoot, relwd string, codegenDebug bool) (buildDir string, err error)
- func (mgr *Manager) ExecScript(ctx context.Context, p ExecScriptParams) (err error)
- func (mgr *Manager) FindProc(procID string) *Proc
- func (mgr *Manager) FindRunByAppID(appID string) *Run
- func (mgr *Manager) ListRuns() []*Run
- func (mgr *Manager) RunError(r *Run, err *errlist.List)
- func (mgr *Manager) RunStderr(r *Run, out []byte)
- func (mgr *Manager) RunStdout(r *Run, out []byte)
- func (mgr *Manager) Start(ctx context.Context, params StartParams) (run *Run, err error)
- func (mgr *Manager) Test(ctx context.Context, params TestParams) (err error)
- type Proc
- type ResourceServer
- type ResourceServices
- func (rs *ResourceServices) GetPubSub() *pubsub.NSQDaemon
- func (rs *ResourceServices) GetRedis() *redis.Server
- func (rs *ResourceServices) GetSQLCluster() *sqldb.Cluster
- func (rs *ResourceServices) StartPubSub(ctx context.Context) error
- func (rs *ResourceServices) StartRedis(ctx context.Context) error
- func (rs *ResourceServices) StartRequiredServices(a *AsyncBuildJobs, parse *parser.Result) error
- func (rs *ResourceServices) StartSQLCluster(a *AsyncBuildJobs, parse *parser.Result) func(ctx context.Context) error
- func (rs *ResourceServices) StopAll()
- type Run
- type RunLogger
- type StartParams
- type StartProcParams
- type TestParams
Constants ¶
const TestHeaderDisablePlatformAuth = "X-Encore-Test-Disable-Platform-Auth"
Variables ¶
This section is empty.
Functions ¶
func GenID ¶ added in v1.8.0
func GenID() string
GenID generates a random run/process id. It panics if it cannot get random bytes.
func IgnoreEvents ¶ added in v1.11.0
IgnoreEvents will return true if _all_ events are on files that should be ignored as the do not impact the running app, or are the result of Encore itself generating code.
Types ¶
type AsyncBuildJobs ¶ added in v1.11.0
type AsyncBuildJobs struct {
// contains filtered or unexported fields
}
func NewAsyncBuildJobs ¶ added in v1.11.0
func (*AsyncBuildJobs) Wait ¶ added in v1.11.0
func (a *AsyncBuildJobs) Wait() error
type EventListener ¶
type EventListener interface { // OnStart is called when a run starts. OnStart(r *Run) // OnReload is called when a run reloads. OnReload(r *Run) // OnStop is called when a run stops. OnStop(r *Run) // OnStdout is called when a run outputs something on stdout. OnStdout(r *Run, out []byte) // OnStderr is called when a run outputs something on stderr. OnStderr(r *Run, out []byte) // OnError is called when a run encounters an error. OnError(r *Run, err *errlist.List) }
EventListener is the interface for listening to events about running apps.
type ExecScriptParams ¶ added in v1.11.0
type ExecScriptParams struct { // App is the app to execute the script for. App *apps.Instance // ScriptRelPath is the path holding the command, from the app root. // It's either a directory or a files. ScriptRelPath string // ScriptArgs are the arguments to pass to the script binary. ScriptArgs []string // WorkingDir is the working dir to execute the script from. // It's relative to the app root. WorkingDir string // Environ are the environment variables to set when running the tests, // in the same format as os.Environ(). Environ []string // Stdout and Stderr are where "go test" output should be written. Stdout, Stderr io.Writer OpTracker *optracker.OpTracker }
ExecScriptParams groups the parameters for the ExecScript method.
type Manager ¶
type Manager struct { RuntimePort int // port for Encore runtime DBProxyPort int // port for sqldb proxy DashPort int // port for dev dashboard Secret *secret.Manager ClusterMgr *sqldb.ClusterManager // contains filtered or unexported fields }
Manager manages the set of running applications.
func (*Manager) AddListener ¶
func (mgr *Manager) AddListener(ln EventListener)
AddListener adds an event listener to mgr. It must be called before starting the first run.
func (*Manager) Check ¶
func (mgr *Manager) Check(ctx context.Context, appRoot, relwd string, codegenDebug bool) (buildDir string, err error)
Check checks the app for errors. It reports a buildDir (if available) when codegenDebug is true.
func (*Manager) ExecScript ¶ added in v1.11.0
func (mgr *Manager) ExecScript(ctx context.Context, p ExecScriptParams) (err error)
ExecScript executes the script.
func (*Manager) FindProc ¶
FindProc finds the proc with the given id. It reports nil if no such proc was found.
func (*Manager) FindRunByAppID ¶
FindRunByAppID finds the run with the given app id. It reports nil if no such run was found.
type Proc ¶
type Proc struct { ID string // unique process id Run *Run // the run the process belongs to Pid int // the OS process id Meta *meta.Data // app metadata snapshot Started time.Time // when the process started Experiments *experiments.Set // enabled experiments Client *yamux.Session // contains filtered or unexported fields }
Proc represents a running Encore process.
func (*Proc) Close ¶ added in v1.8.0
func (p *Proc) Close()
Close closes the process and waits for it to shutdown. It can safely be called multiple times.
type ResourceServer ¶ added in v1.3.0
type ResourceServer interface {
Stop() // Shutdown the resource
}
type ResourceServices ¶ added in v1.3.0
type ResourceServices struct {
// contains filtered or unexported fields
}
ResourceServices represent the set of servers/services we have started up to support the running Encore application.
func NewResourceServices ¶ added in v1.11.0
func NewResourceServices(app *apps.Instance, sqlMgr *sqldb.ClusterManager) *ResourceServices
func (*ResourceServices) GetPubSub ¶ added in v1.3.0
func (rs *ResourceServices) GetPubSub() *pubsub.NSQDaemon
GetPubSub returns the PubSub daemon if it is running otherwise it returns nil
func (*ResourceServices) GetRedis ¶ added in v1.7.0
func (rs *ResourceServices) GetRedis() *redis.Server
GetRedis returns the Redis server if it is running otherwise it returns nil
func (*ResourceServices) GetSQLCluster ¶ added in v1.3.0
func (rs *ResourceServices) GetSQLCluster() *sqldb.Cluster
GetSQLCluster returns the SQL cluster
func (*ResourceServices) StartPubSub ¶ added in v1.3.0
func (rs *ResourceServices) StartPubSub(ctx context.Context) error
StartPubSub starts a PubSub daemon.
func (*ResourceServices) StartRedis ¶ added in v1.7.0
func (rs *ResourceServices) StartRedis(ctx context.Context) error
StartRedis starts a Redis server.
func (*ResourceServices) StartRequiredServices ¶ added in v1.3.0
func (rs *ResourceServices) StartRequiredServices(a *AsyncBuildJobs, parse *parser.Result) error
StartRequiredServices will start the required services for the current application if they are not already running based on the given parse result
func (*ResourceServices) StartSQLCluster ¶ added in v1.3.0
func (rs *ResourceServices) StartSQLCluster(a *AsyncBuildJobs, parse *parser.Result) func(ctx context.Context) error
func (*ResourceServices) StopAll ¶ added in v1.3.0
func (rs *ResourceServices) StopAll()
type Run ¶
type Run struct { ID string // unique ID for this instance of the running app App *apps.Instance ListenAddr string // the address the app is listening on ResourceServers *ResourceServices Mgr *Manager // contains filtered or unexported fields }
Run represents a running Encore application.
func (*Run) Done ¶
func (r *Run) Done() <-chan struct{}
Done returns a channel that is closed when the run is closed.
func (*Run) Proc ¶
Proc returns the current running process. It may have already exited. If the proc has not yet started it may return nil.
func (*Run) Reload ¶
Reload rebuilds the app and, if successful, starts a new proc and switches over.
func (*Run) ServeHTTP ¶
func (r *Run) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements http.Handler by forwarding the request to the currently running process.
type RunLogger ¶ added in v1.10.0
RunLogger is the interface for listening to run logs. The log methods are called for each logline on stdout and stderr respectively.
type StartParams ¶
type StartParams struct { // App is the app to start. App *apps.Instance // WorkingDir is the working dir, for formatting // error messages with relative paths. WorkingDir string // Watch enables watching for code changes for live reloading. Watch bool Listener net.Listener // listener to use ListenAddr string // address we're listening on // Environ are the environment variables to set for the running app, // in the same format as os.Environ(). Environ []string // The Ops tracker being used for this run OpsTracker *optracker.OpTracker }
StartParams groups the parameters for the Run method.
type StartProcParams ¶ added in v1.8.0
type StartProcParams struct { Ctx context.Context BuildDir string BinPath string Meta *meta.Data Secrets map[string]string ServiceConfigs map[string]string RuntimePort int DBProxyPort int SQLDBCluster *sqldb.Cluster // nil means no cluster NSQDaemon *pubsub.NSQDaemon // nil means no pubsub Redis *redis.Server // nil means no redis Logger RunLogger Environ []string Experiments *experiments.Set }
type TestParams ¶
type TestParams struct { // App is the app to test. App *apps.Instance // SQLDBCluster is the SQLDB cluster to use, if any. SQLDBCluster *sqldb.Cluster // WorkingDir is the working dir, for formatting // error messages with relative paths. WorkingDir string // Parse is the parse result for the initial run of the app. // It must be set. Parse *parser.Result // Args are the arguments to pass to "go test". Args []string // Environ are the environment variables to set when running the tests, // in the same format as os.Environ(). Environ []string // Stdout and Stderr are where "go test" output should be written. Stdout, Stderr io.Writer }
TestParams groups the parameters for the Test method.