supervise providers and reflect terminal state
This commit is contained in:
+28
-17
@@ -80,6 +80,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
mux := http.NewServeMux()
|
||||
providerHealth := map[string]*provider.Supervisor{}
|
||||
surface := func(r *http.Request) authz.Surface {
|
||||
v := authz.ParseSurface(r.Header.Get("X-Orchestra-Surface"))
|
||||
if v == "" {
|
||||
@@ -321,29 +322,39 @@ func main() {
|
||||
}
|
||||
json.NewEncoder(w).Encode(map[string]any{"ready": ready, "checks": checks})
|
||||
})
|
||||
mux.HandleFunc("/v1/providers/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
out := map[string]provider.Health{}
|
||||
for name, sup := range providerHealth {
|
||||
out[name] = sup.Health()
|
||||
}
|
||||
json.NewEncoder(w).Encode(out)
|
||||
})
|
||||
if base := os.Getenv("ORCHESTRA_GITEA_URL"); base != "" {
|
||||
g := provider.Gitea{BaseURL: base, Token: os.Getenv("ORCHESTRA_GITEA_TOKEN"), WebhookSecret: os.Getenv("ORCHESTRA_GITEA_WEBHOOK_SECRET"), Owner: os.Getenv("ORCHESTRA_GITEA_OWNER"), Repo: os.Getenv("ORCHESTRA_GITEA_REPO")}
|
||||
mux.Handle("/v1/providers/gitea/webhook", g.WebhookHandler(s))
|
||||
go func() {
|
||||
for {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
_, e := g.Poll(ctx, s)
|
||||
cancel()
|
||||
if e != nil {
|
||||
log.Printf("gitea poll: %v", e)
|
||||
reflecting := provider.ReflectingSink{Sink: s, Tasks: s, Reflector: g}
|
||||
mux.Handle("/v1/providers/gitea/webhook", g.WebhookHandler(reflecting))
|
||||
sup := &provider.Supervisor{Name: "gitea", Run: func(ctx context.Context) error {
|
||||
pollCtx, cancel := context.WithTimeout(ctx, time.Minute)
|
||||
defer cancel()
|
||||
_, err := g.Poll(pollCtx, reflecting)
|
||||
if err == nil {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-time.After(time.Minute):
|
||||
}
|
||||
time.Sleep(time.Minute)
|
||||
}
|
||||
}()
|
||||
return err
|
||||
}}
|
||||
sup.Start(context.Background())
|
||||
providerHealth["gitea"] = sup
|
||||
}
|
||||
if path := os.Getenv("ORCHESTRA_JSONL"); path != "" {
|
||||
go func() {
|
||||
ctx := context.Background()
|
||||
err := (provider.JSONLWatcher{Path: path, Interval: time.Second, Provider: provider.JSONL{Source: "jsonl"}}).Run(ctx, s)
|
||||
if err != nil {
|
||||
log.Printf("jsonl provider: %v", err)
|
||||
}
|
||||
}()
|
||||
sup := &provider.Supervisor{Name: "jsonl", Run: func(ctx context.Context) error {
|
||||
return (provider.JSONLWatcher{Path: path, Interval: time.Second, Provider: provider.JSONL{Source: "jsonl"}}).Run(ctx, s)
|
||||
}}
|
||||
sup.Start(context.Background())
|
||||
providerHealth["jsonl"] = sup
|
||||
}
|
||||
port := os.Getenv("ORCHESTRA_PORT")
|
||||
if port == "" {
|
||||
|
||||
Reference in New Issue
Block a user