working workers in browser

This commit is contained in:
Barak Michener 2020-12-04 20:45:19 -08:00
parent 56116aea2a
commit 715f79c9c0
13 changed files with 343 additions and 28 deletions

View file

@ -2,9 +2,9 @@ package main
import (
"errors"
"fmt"
"github.com/barakmich/tinkerbell/ray_rpc"
"go.uber.org/zap"
)
type WorkstreamConnection = ray_rpc.RayletWorkerConnection_WorkstreamServer
@ -13,6 +13,7 @@ type Worker interface {
AssignWork(work *ray_rpc.Work) error
Run() error
Close() error
Schedulable() bool
}
type SimpleWorker struct {
@ -21,6 +22,10 @@ type SimpleWorker struct {
pool WorkerPool
}
func (s *SimpleWorker) Schedulable() bool {
return true
}
func (s *SimpleWorker) AssignWork(work *ray_rpc.Work) error {
s.workChan <- work
return nil
@ -39,13 +44,13 @@ func (w *SimpleWorker) Run() error {
if sentinel.Status != ray_rpc.READY {
return errors.New("Sent wrong sentinel? Closing...")
}
fmt.Println("New worker:", sentinel.ErrorMsg)
zap.S().Info("New worker:", sentinel.ErrorMsg)
go func() {
for work := range w.workChan {
fmt.Println("sending work")
zap.S().Debug("Sending work")
err = w.clientConn.Send(work)
if err != nil {
fmt.Println("Error sending:", err)
zap.S().Error("Error sending:", err)
return
}
}
@ -53,12 +58,12 @@ func (w *SimpleWorker) Run() error {
for {
result, err := w.clientConn.Recv()
if err != nil {
fmt.Println("Error on channel:", err)
zap.S().Error("Error on channel:", err)
return err
}
err = w.pool.Finish(result)
if err != nil {
fmt.Println("Error finishing:", err)
zap.S().Error("Error finishing:", err)
return err
}
}