Skip to content

Commit e916764

Browse files
committed
Added status streaming to Init grpc call
This will be useful in the next commits
1 parent 35f0c05 commit e916764

File tree

6 files changed

+197
-123
lines changed

6 files changed

+197
-123
lines changed

cli/cli.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func packageManagerInitReq() *rpc.InitReq {
8686
func InitInstance() *rpc.InitResp {
8787
logrus.Info("Initializing package manager")
8888
req := packageManagerInitReq()
89-
resp, err := commands.Init(context.Background(), req)
89+
resp, err := commands.Init(context.Background(), req, OutputProgressBar(), OutputTaskProgress())
9090
if err != nil {
9191
formatter.PrintError(err, "Error initializing package manager")
9292
os.Exit(ErrGeneric)

commands/instances.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func GetLibraryManager(req InstanceContainer) *librariesmanager.LibrariesManager
7272
return i.lm
7373
}
7474

75-
func Init(ctx context.Context, req *rpc.InitReq) (*rpc.InitResp, error) {
75+
func Init(ctx context.Context, req *rpc.InitReq, downloadCB DownloadProgressCB, taskCB TaskProgressCB) (*rpc.InitResp, error) {
7676
inConfig := req.GetConfiguration()
7777
if inConfig == nil {
7878
return nil, fmt.Errorf("invalid request")

daemon/client/client.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func main() {
4646

4747
// INIT
4848
fmt.Println("=== calling Init")
49-
initResp, err := client.Init(context.Background(), &rpc.InitReq{
49+
initRespStream, err := client.Init(context.Background(), &rpc.InitReq{
5050
Configuration: &rpc.Configuration{
5151
DataDir: datadir,
5252
},
@@ -55,9 +55,28 @@ func main() {
5555
fmt.Printf("Error creating server instance: %s\n", err)
5656
os.Exit(1)
5757
}
58-
instance := initResp.GetInstance()
59-
fmt.Printf("---> %+v\n", initResp)
60-
fmt.Println()
58+
var instance *rpc.Instance
59+
for {
60+
initResp, err := initRespStream.Recv()
61+
if err == io.EOF {
62+
fmt.Println()
63+
break
64+
}
65+
if err != nil {
66+
fmt.Printf("Init error: %s\n", err)
67+
os.Exit(1)
68+
}
69+
if initResp.GetInstance() != nil {
70+
instance = initResp.GetInstance()
71+
fmt.Printf("---> %+v\n", initResp)
72+
}
73+
if initResp.GetDownloadProgress() != nil {
74+
fmt.Printf(">> DOWNLOAD: %s\n", initResp.GetDownloadProgress())
75+
}
76+
if initResp.GetTaskProgress() != nil {
77+
fmt.Printf(">> TASK: %s\n", initResp.GetTaskProgress())
78+
}
79+
}
6180

6281
// UPDATE-INDEX
6382
fmt.Println("=== calling UpdateIndex")

daemon/daemon.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,16 @@ func (s *ArduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesInd
103103
return stream.Send(&rpc.UpdateLibrariesIndexResp{})
104104
}
105105

106-
func (s *ArduinoCoreServerImpl) Init(ctx context.Context, req *rpc.InitReq) (*rpc.InitResp, error) {
107-
return commands.Init(ctx, req)
106+
func (s *ArduinoCoreServerImpl) Init(req *rpc.InitReq, stream rpc.ArduinoCore_InitServer) error {
107+
resp, err := commands.Init(stream.Context(), req,
108+
func(p *rpc.DownloadProgress) { stream.Send(&rpc.InitResp{DownloadProgress: p}) },
109+
func(p *rpc.TaskProgress) { stream.Send(&rpc.InitResp{TaskProgress: p}) },
110+
)
111+
if err != nil {
112+
return err
113+
}
114+
fmt.Println(resp)
115+
return stream.Send(resp)
108116
}
109117

110118
func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoCore_CompileServer) error {

0 commit comments

Comments
 (0)