run

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: MPL-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package run starts and tracks running Encore applications.

Index

Constants

View Source
const BasePort = 4060

BasePort is the default port Encore apps start listening on.

Variables

This section is empty.

Functions

This section is empty.

Types

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)
}

EventListener is the interface for listening to events about running apps.

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
	// 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) error

Check checks the app for errors.

func (*Manager) FindProc

func (mgr *Manager) FindProc(procID string) *Proc

FindProc finds the proc with the given id. It reports nil if no such proc was found.

func (*Manager) FindRunByAppID

func (mgr *Manager) FindRunByAppID(appID string) *Run

FindRunByAppID finds the run with the given app id. It reports nil if no such run was found.

func (*Manager) ListRuns

func (mgr *Manager) ListRuns() []*Run

ListRuns provides a snapshot of all runs.

func (*Manager) Start

func (mgr *Manager) Start(ctx context.Context, params StartParams) (run *Run, err error)

Start starts the application. Its lifetime is bounded by ctx.

func (*Manager) Test

func (mgr *Manager) Test(ctx context.Context, params TestParams) (err error)

Test runs the tests.

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
	// contains filtered or unexported fields
}

Proc represents a running Encore process.

func (*Proc) Done

func (p *Proc) Done() <-chan struct{}

Done returns a channel that is closed when the process has exited.

type Run

type Run struct {
	ID      string // unique ID for this instance of the running app
	AppID   string // unique identifier for the app
	AppSlug string // the optional app slug, if linked to encore.dev
	Root    string // the filesystem path to the app root
	Port    int    // the port the app is listening on
	// 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

func (r *Run) Proc() *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

func (r *Run) Reload() (*Proc, error)

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 StartParams

type StartParams struct {
	// AppRoot is the application root.
	AppRoot string

	// AppID is the unique app id, as defined by the manifest.
	AppID string

	// WorkingDir is the working dir, for formatting
	// error messages with relative paths.
	WorkingDir string

	// DBClusterID is the database cluster id to connect to.
	DBClusterID string

	// Parse is the parse result for the initial run of the app.
	// If nil the app is parsed before starting.
	Parse *parser.Result

	// Watch enables watching for code changes for live reloading.
	Watch bool
}

StartParams groups the parameters for the Run method.

type TestParams

type TestParams struct {
	// AppRoot is the application root.
	AppRoot string

	// AppID is the unique app id, as defined by the manifest.
	AppID string

	// WorkingDir is the working dir, for formatting
	// error messages with relative paths.
	WorkingDir string

	// DBClusterID is the database cluster id to connect to.
	DBClusterID string

	// Parse is the parse result for the initial run of the app.
	// If nil the app is parsed before starting.
	Parse *parser.Result

	// Args are the arguments to pass to "go test".
	Args []string

	// Stdout and Stderr are where "go test" output should be written.
	Stdout, Stderr io.Writer
}

TestParams groups the parameters for the Test method.

Jump to

Keyboard shortcuts

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