Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
add UI
Browse files Browse the repository at this point in the history
  • Loading branch information
thdxr committed Feb 8, 2024
1 parent e71fb0c commit 2ca6d11
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 10 deletions.
2 changes: 2 additions & 0 deletions cmd/sst/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ func main() {
)
}
}

u.Event(&event)
},
})

Expand Down
24 changes: 24 additions & 0 deletions cmd/sst/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/fatih/color"
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/sst/ion/pkg/project"
"github.com/sst/ion/pkg/server"
)

type ProgressMode string
Expand Down Expand Up @@ -310,6 +311,29 @@ func (u *UI) Trigger(evt *project.StackEvent) {
}
}

func (u *UI) Event(evt *server.Event) {

if evt.FunctionInvokedEvent != nil {
if u.spinner.Enabled() {
u.spinner.Disable()
defer u.spinner.Enable()
}
color.New(color.FgMagenta, color.Bold).Print("| ")
color.New(color.FgHiBlack).Print(fmt.Sprintf("%-11s", evt.FunctionInvokedEvent.FunctionID), " ", "Invoked")
fmt.Println()
}

if evt.FunctionResponseEvent != nil {
if u.spinner.Enabled() {
u.spinner.Disable()
defer u.spinner.Enable()
}
color.New(color.FgGreen, color.Bold).Print("| ")
color.New(color.FgHiBlack).Print(fmt.Sprintf("%-11s", evt.FunctionResponseEvent.FunctionID), " ", "Success")
fmt.Println()
}
}

func (u *UI) Interrupt() {
u.spinner.Suffix = " Interrupting..."
}
Expand Down
4 changes: 1 addition & 3 deletions examples/test/src/index.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Resource } from "sst";

export async function handler() {
return {
statusCode: 200,
body: process.cwd(),
body: "why",
};
}
1 change: 0 additions & 1 deletion pkg/runtime/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (r *NodeRuntime) Build(ctx context.Context, input *BuildInput) (*BuildOutpu
return nil, err
}
target := filepath.Join(input.Out(), strings.ReplaceAll(rel, filepath.Ext(rel), extension))
slog.Info("building", "from", file, "to", target)

options := esbuild.BuildOptions{
EntryPoints: []string{file},
Expand Down
1 change: 1 addition & 0 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func GetRuntime(input string) (Runtime, bool) {

func Build(ctx context.Context, input *BuildInput) (*BuildOutput, error) {
slog.Info("building function", "runtime", input.Runtime, "functionID", input.FunctionID)
defer slog.Info("function built", "runtime", input.Runtime, "functionID", input.FunctionID)
runtime, ok := GetRuntime(input.Runtime)
if !ok {
return nil, fmt.Errorf("Runtime not found: %v", input.Runtime)
Expand Down
36 changes: 33 additions & 3 deletions pkg/server/dev/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ type fragment struct {
Data string `json:"data"`
}

type FunctionInvokedEvent struct {
FunctionID string
WorkerID string
}

type FunctionResponseEvent struct {
FunctionID string
WorkerID string
}

func Start(
ctx context.Context,
mux *http.ServeMux,
Expand Down Expand Up @@ -145,7 +155,9 @@ func Start(
initChan := make(chan MQTT.Message, 1000)
shutdownChan := make(chan MQTT.Message, 1000)
fileChan := make(chan *watcher.FileChangedEvent, 1000)
workerShutdown := make(chan *WorkerInfo, 1000)
workerShutdownChan := make(chan *WorkerInfo, 1000)
workerInvokedChan := make(chan string, 1000)
workerResponseChan := make(chan string, 1000)

bus.Subscribe(ctx, func(event *project.StackEvent) {
if event.CompleteEvent != nil {
Expand Down Expand Up @@ -205,7 +217,7 @@ func Start(
}
go func() {
worker.Done()
workerShutdown <- info
workerShutdownChan <- info
}()
workers[workerID] = info
}
Expand All @@ -214,7 +226,19 @@ func Start(
select {
case <-ctx.Done():
return
case info := <-workerShutdown:
case workerID := <-workerInvokedChan:
info := workers[workerID]
bus.Publish(&FunctionInvokedEvent{
FunctionID: info.FunctionID,
WorkerID: info.WorkerID,
})
case workerID := <-workerResponseChan:
info := workers[workerID]
bus.Publish(&FunctionResponseEvent{
FunctionID: info.FunctionID,
WorkerID: info.WorkerID,
})
case info := <-workerShutdownChan:
slog.Info("worker died", "workerID", info.WorkerID)
existing, ok := workers[info.WorkerID]
if !ok {
Expand Down Expand Up @@ -334,6 +358,12 @@ func Start(
if err != nil {
fmt.Println("Error writing to the connection:", err)
}
if path[len(path)-1] == "next" {
workerInvokedChan <- workerID
}
if path[len(path)-1] == "response" {
workerResponseChan <- workerID
}
done <- struct{}{}
}()

Expand Down
16 changes: 13 additions & 3 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ type State struct {

type Event struct {
project.StackEvent
StateEvent *StateEvent
StateEvent *StateEvent
FunctionInvokedEvent *aws.FunctionInvokedEvent
FunctionResponseEvent *aws.FunctionResponseEvent
}

type StateEvent struct {
Expand Down Expand Up @@ -82,8 +84,6 @@ func (s *Server) Start(parentContext context.Context) error {
ctx, cancel := context.WithCancel(parentContext)
defer cancel()

// warps := project.Warps{}

mux := http.NewServeMux()

var count int64
Expand All @@ -109,6 +109,16 @@ func (s *Server) Start(parentContext context.Context) error {
},
})
publish(s.lastEvent)
bus.Subscribe(ctx, func(event *aws.FunctionInvokedEvent) {
publish(&Event{
FunctionInvokedEvent: event,
})
})
bus.Subscribe(ctx, func(event *aws.FunctionResponseEvent) {
publish(&Event{
FunctionResponseEvent: event,
})
})
bus.Subscribe(ctx, func(event *project.StackEvent) {
publish(&Event{
StackEvent: *event,
Expand Down

0 comments on commit 2ca6d11

Please sign in to comment.