Skip to content

Commit

Permalink
extension/cmd: test extension server before integrating witih savvy r…
Browse files Browse the repository at this point in the history
…ecord and savvy record history

Signed-off-by: Shantanu <[email protected]>
  • Loading branch information
joshi4 committed Jan 24, 2025
1 parent 2129a4a commit fe7eda3
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions extension/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"context"
"fmt"
"os"
"os/signal"
"syscall"

"github.com/getsavvyinc/savvy-cli/extension"
)

func main() {
// Create a context that we'll cancel on signal
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Set up signal handling
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)

// Create and start the server
processor := func(items []extension.HistoryItem) error {
for _, item := range items {
fmt.Printf("Processing item: %s\n", item.URL)
}
return nil
}

server := extension.New(processor)
if err := server.Start(ctx); err != nil {
fmt.Printf("Error starting server: %v\n", err)
os.Exit(1)
}

// Wait for signal
sig := <-sigChan
fmt.Printf("\nReceived signal: %v\n", sig)
fmt.Println("Shutting down server...")

// Cancel context to trigger graceful shutdown
cancel()

// Wait for server to close
if err := server.Close(); err != nil {
fmt.Printf("Error during shutdown: %v\n", err)
os.Exit(1)
}

fmt.Println("Server shutdown complete")
}

0 comments on commit fe7eda3

Please sign in to comment.