shad-go/distbuild/pkg/worker/worker.go

74 lines
1.3 KiB
Go
Raw Normal View History

2020-03-10 12:08:59 +00:00
package worker
import (
"context"
2020-03-11 22:46:45 +00:00
"net/http"
2020-03-10 12:08:59 +00:00
"sync"
2020-03-11 22:46:45 +00:00
"go.uber.org/zap"
2020-03-10 12:08:59 +00:00
"gitlab.com/slon/shad-go/distbuild/pkg/artifact"
"gitlab.com/slon/shad-go/distbuild/pkg/build"
"gitlab.com/slon/shad-go/distbuild/pkg/filecache"
)
type Worker struct {
2020-03-11 22:46:45 +00:00
coordinatorEndpoint string
log *zap.Logger
fileCache *filecache.Cache
artifacts *artifact.Cache
2020-03-10 12:08:59 +00:00
2020-03-11 22:46:45 +00:00
mux *http.ServeMux
2020-03-10 12:08:59 +00:00
mu sync.Mutex
newArtifacts []build.ID
newSources []build.ID
}
2020-03-11 22:46:45 +00:00
func New(
coordinatorEndpoint string,
log *zap.Logger,
fileCache *filecache.Cache,
artifacts *artifact.Cache,
) *Worker {
return &Worker{
coordinatorEndpoint: coordinatorEndpoint,
log: log,
fileCache: fileCache,
artifacts: artifacts,
mux: http.NewServeMux(),
}
}
func (w *Worker) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
w.mux.ServeHTTP(rw, r)
}
2020-03-10 12:08:59 +00:00
func (w *Worker) recover() error {
2020-03-11 22:46:45 +00:00
err := w.fileCache.Range(func(file build.ID) error {
2020-03-10 12:08:59 +00:00
w.newSources = append(w.newSources, file)
return nil
})
if err != nil {
return err
}
2020-03-11 22:46:45 +00:00
return w.artifacts.Range(func(file build.ID) error {
2020-03-10 12:08:59 +00:00
w.newArtifacts = append(w.newArtifacts, file)
return nil
})
}
func (w *Worker) Run(ctx context.Context) error {
if err := w.recover(); err != nil {
return err
}
for {
}
}