diff --git a/pkg/service/dummy.go b/pkg/service/dummy.go deleted file mode 100644 index 264a0d48c..000000000 --- a/pkg/service/dummy.go +++ /dev/null @@ -1,23 +0,0 @@ -// (c) Cartesi and individual authors (see AUTHORS) -// SPDX-License-Identifier: Apache-2.0 (see LICENSE) - -package service - -// A Service implementation that does nothing -type DummyService struct { - Service -} - -type CreateDummyInfo struct { - CreateInfo -} - -func CreateDummy(ci CreateDummyInfo, null *DummyService) error { - return Create(&ci.CreateInfo, &null.Service) -} - -func (s *DummyService) Alive() bool { return true } -func (s *DummyService) Ready() bool { return true } -func (s *DummyService) Reload() []error { return nil } -func (s *DummyService) Tick() []error { return nil } -func (s *DummyService) Stop(bool) []error { return nil } diff --git a/pkg/service/list.go b/pkg/service/list.go deleted file mode 100644 index f4ae96709..000000000 --- a/pkg/service/list.go +++ /dev/null @@ -1,148 +0,0 @@ -// (c) Cartesi and individual authors (see AUTHORS) -// SPDX-License-Identifier: Apache-2.0 (see LICENSE) - -package service - -import ( - "fmt" - "net/http" - "strings" - "time" -) - -// A Service implementation in terms of a list of other services -type ListService struct { - Service - Children []*Service -} - -type CreateListInfo struct { - CreateInfo -} - -func CreateList(ci CreateListInfo, list *ListService) error { - err := Create(&ci.CreateInfo, &list.Service) - if err != nil { - return err - } - - if ci.CreateInfo.TelemetryCreate { - list.ServeMux.Handle("/"+list.Name+"/readyz", - http.HandlerFunc(list.ReadyHandler)) - list.ServeMux.Handle("/"+list.Name+"/livez", - http.HandlerFunc(list.AliveHandler)) - } - return nil -} - -func (me *ListService) Alive() bool { - alive := true - for _, s := range me.Children { - alive = alive && s.Alive() - } - return alive -} - -func (me *ListService) Ready() bool { - allReady := true - for _, s := range me.Children { - ready := s.Ready() - allReady = allReady && ready - } - return allReady -} - -func (me *ListService) Reload() []error { - var all []error - for _, s := range me.Children { - es := s.Reload() - all = append(all, es...) - } - return all -} - -/* -// Simple tick runs children one at a time -func (me *ListService) Tick() []error { - var all []error - for _, s := range me.Children { - all = append(all, s.Tick()...) - } - return all -} -*/ - -// * -func (me *ListService) Tick() []error { - c := make(chan []error) - var all []error - for _, s := range me.Children { - go func() { - c <- s.Tick() - }() - } - - limit := time.Duration(0.95 * float64(me.Service.PollInterval)) - deadline := time.After(limit) - for range me.Children { - select { - case errs := <-c: - all = append(all, errs...) - case <-deadline: - me.Logger.Warn("Tick:time limit exceeded", - "service", me.Name, - "limit", limit) - return all - } - } - return all -} - -//*/ - -func (me *ListService) Stop(force bool) []error { - var all []error - for _, s := range me.Children { - es := s.Stop(force) - all = append(all, es...) - } - return all -} - -func (me *ListService) AliveHandler(w http.ResponseWriter, r *http.Request) { - ss := []string{} - - allAlive := true - for _, s := range me.Children { - alive := s.Alive() - allAlive = allAlive && alive - ss = append(ss, fmt.Sprintf("%s: %v", s.Name, alive)) - } - ss = append(ss, fmt.Sprintf("%s: %v", me.Name, allAlive)) - - if allAlive { - http.Error(w, strings.Join(ss, "\n"), - http.StatusInternalServerError) - } else { - fmt.Fprintf(w, strings.Join(ss, "\n")) - } -} - -func (me *ListService) ReadyHandler(w http.ResponseWriter, r *http.Request) { - ss := []string{} - - allReady := true - for _, s := range me.Children { - ready := s.Ready() - allReady = allReady && ready - ss = append(ss, fmt.Sprintf("%s: %v", s.Name, ready)) - } - ss = append(ss, fmt.Sprintf("%s: %v", me.Name, allReady)) - - if allReady { - http.Error(w, strings.Join(ss, "\n"), - http.StatusInternalServerError) - } else { - fmt.Fprintf(w, strings.Join(ss, "\n")) - } -} diff --git a/pkg/service/slow.go b/pkg/service/slow.go deleted file mode 100644 index 6dd843b31..000000000 --- a/pkg/service/slow.go +++ /dev/null @@ -1,43 +0,0 @@ -// (c) Cartesi and individual authors (see AUTHORS) -// SPDX-License-Identifier: Apache-2.0 (see LICENSE) - -package service - -import "time" - -// A Service implementation that takes time to Tick -type SlowService struct { - Service - Time time.Duration -} - -type CreateSlowInfo struct { - CreateInfo - Time time.Duration -} - -func CreateSlow(ci CreateSlowInfo, slow *SlowService) error { - slow.Time = ci.Time - return Create(&ci.CreateInfo, &slow.Service) -} - -func (me *SlowService) Alive() bool { - return true -} - -func (me *SlowService) Ready() bool { - return true -} - -func (me *SlowService) Reload() []error { - return nil -} - -func (me *SlowService) Tick() []error { - time.Sleep(me.Time) - return nil -} - -func (me *SlowService) Stop(bool) []error { - return nil -}