events

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoData = struct{}{}

Functions

func NewCLILogger

func NewCLILogger(verbosity int, w io.Writer) logging.Logger

func NewCapturingEmitter

func NewCapturingEmitter() *capturingEmitter

func NewCliEmitter

func NewCliEmitter(w io.Writer, log logging.Logger) *cliEmitter

func NewDataEmitter

func NewDataEmitter(data EventData, emitter Emitter) *dataEmitter

func NewLoggerWithSSE

func NewLoggerWithSSE(verbosity int, emitter *SSEEmitter) logging.Logger

func NewMockEmitter

func NewMockEmitter() *mockEmitter

func NewNullEmitter

func NewNullEmitter() *nullEmitter

Types

type Emitter

type Emitter interface {
	Emit(*Event) error
}

type ErrorCode

type ErrorCode = types.ErrorCode
const (
	NoError                   ErrorCode = ""
	AuthenticationFailedCode  ErrorCode = "authFailedErr"            // Couldn't authenticate to publishing server
	PermissionsCode           ErrorCode = "permissionErr"            // Server responded with 403 forbidden
	OperationTimedOutCode     ErrorCode = "timeoutErr"               // HTTP request to publishing server timed out
	ConnectionFailedCode      ErrorCode = "connectionFailed"         // Couldn't connect to Connect
	ServerErrorCode           ErrorCode = "serverErr"                // HTTP 5xx code from publishing server
	VanityURLNotAvailableCode ErrorCode = "vanityURLNotAvailableErr" // Vanity URL already in use
	DeploymentNotFoundCode    ErrorCode = "deploymentNotFoundErr"    // Could not find deployment to update
	AppModeNotModifiableCode  ErrorCode = "appModeNotModifiableErr"  // attempt to deploy to an existing deployment with a non-matching app mode

	// Server failed to deploy the bundle.
	// This will eventually need to become more specific
	// so we can give better guidance.
	DeploymentFailedCode ErrorCode = "deployFailed"
)

type Event

type Event struct {
	Time    time.Time
	Type    EventType
	Data    EventData
	ErrCode ErrorCode
	// contains filtered or unexported fields
}

func New

func New(op Operation, phase Phase, errCode ErrorCode, data any) *Event

func NewErrorEvent

func NewErrorEvent(e types.EventableError) Event

type EventData

type EventData = types.ErrorData

type EventType

type EventType = string

func EventTypeOf

func EventTypeOf(op Operation, phase Phase) EventType

type MockSSEServer

type MockSSEServer struct {
	mock.Mock
}

func NewMockSSEServer

func NewMockSSEServer() *MockSSEServer

func (*MockSSEServer) Close

func (m *MockSSEServer) Close()

func (*MockSSEServer) CreateStream

func (m *MockSSEServer) CreateStream(id string) *sse.Stream

func (*MockSSEServer) Publish

func (m *MockSSEServer) Publish(id string, event *sse.Event)

func (*MockSSEServer) RemoveStream

func (m *MockSSEServer) RemoveStream(id string)

func (*MockSSEServer) StreamExists

func (m *MockSSEServer) StreamExists(id string) bool

func (*MockSSEServer) TryPublish

func (m *MockSSEServer) TryPublish(id string, event *sse.Event) bool

type Operation

type Operation = types.Operation

We use Operation and Phase to construct the event Type.

const (
	AgentOp Operation = "agent"

	PublishCheckCapabilitiesOp       Operation = "publish/checkCapabilities"
	PublishGetRPackageDescriptionsOp Operation = "publish/getRPackageDescriptions"
	PublishCreateNewDeploymentOp     Operation = "publish/createNewDeployment"
	PublishSetEnvVarsOp              Operation = "publish/setEnvVars"
	PublishCreateBundleOp            Operation = "publish/createBundle"
	PublishUpdateDeploymentOp        Operation = "publish/createDeployment"
	PublishUploadBundleOp            Operation = "publish/uploadBundle"
	PublishDeployBundleOp            Operation = "publish/deployBundle"
	PublishRestorePythonEnvOp        Operation = "publish/restorePythonEnv"
	PublishRestoreREnvOp             Operation = "publish/restoreREnv"
	PublishRunContentOp              Operation = "publish/runContent"
	PublishSetVanityUrlOp            Operation = "publish/setVanityURL"
	PublishValidateDeploymentOp      Operation = "publish/validateDeployment"
	PublishOp                        Operation = "publish"
)

type Phase

type Phase string

Phase indicates which part of an Operation we are performing

const (
	StartPhase    Phase = "start"
	ProgressPhase Phase = "progress"
	StatusPhase   Phase = "status"
	SuccessPhase  Phase = "success"
	FailurePhase  Phase = "failure"
	LogPhase      Phase = "log"
)

type SSEEmitter

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

func NewSSEEmitter

func NewSSEEmitter(server SSEServer) *SSEEmitter

func (*SSEEmitter) Emit

func (e *SSEEmitter) Emit(event *Event) error

type SSEHandler

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

SSEHandler emits an event for every log message.

func NewSSEHandler

func NewSSEHandler(emitter *SSEEmitter) *SSEHandler

func (*SSEHandler) Enabled

func (h *SSEHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*SSEHandler) Handle

func (h *SSEHandler) Handle(ctx context.Context, rec slog.Record) error

func (*SSEHandler) WithAttrs

func (h *SSEHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*SSEHandler) WithGroup

func (h *SSEHandler) WithGroup(string) slog.Handler

type SSEServer

type SSEServer interface {
	Close()
	CreateStream(id string) *sse.Stream
	RemoveStream(id string)
	StreamExists(id string) bool
	Publish(id string, event *sse.Event)
	TryPublish(id string, event *sse.Event) bool
}

Jump to

Keyboard shortcuts

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