Implement projections and operations

This commit is contained in:
kami
2026-07-26 19:14:46 +04:00
parent 9937cd5cd0
commit 8822e028bb
6 changed files with 148 additions and 7 deletions
+24
View File
@@ -2,10 +2,12 @@ package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"orchestra/internal/authz"
"orchestra/internal/domain"
"orchestra/internal/operations"
"orchestra/internal/registry"
"orchestra/internal/router"
"orchestra/internal/store"
@@ -70,6 +72,28 @@ func main() {
}
json.NewEncoder(w).Encode(s.Events(n))
})
mux.HandleFunc("/v1/brief", func(w http.ResponseWriter, r *http.Request) {
to := time.Now().UTC()
from := to.Add(-12 * time.Hour)
if v, parseErr := time.Parse(time.RFC3339, r.URL.Query().Get("from")); parseErr == nil {
from = v
}
if v, parseErr := time.Parse(time.RFC3339, r.URL.Query().Get("to")); parseErr == nil {
to = v
}
json.NewEncoder(w).Encode(operations.BuildBrief(s.Events(0), from, to, operations.GitState(dir)))
})
mux.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
tasks := s.Tasks()
counts := map[domain.TaskState]int{}
for _, t := range tasks {
counts[t.State]++
}
w.Header().Set("Content-Type", "text/plain; version=0.0.4")
for _, state := range []domain.TaskState{domain.StateQueued, domain.StateLeased, domain.StateCompleted, domain.StateFailed, domain.StateBlocked} {
fmt.Fprintf(w, "orchestra_tasks{state=\"%s\"} %d\n", state, counts[state])
}
})
mux.HandleFunc("/v1/tasks/", func(w http.ResponseWriter, r *http.Request) {
parts := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
if len(parts) < 4 || len(parts) > 5 || r.Method != "POST" {