schedule daily standup advisories
This commit is contained in:
@@ -172,6 +172,31 @@ func main() {
|
||||
}
|
||||
json.NewEncoder(w).Encode(operations.BuildBrief(s.Events(0), from, to, operations.GitState(dir)))
|
||||
})
|
||||
standup := func() (domain.Event, error) {
|
||||
items, _ := json.Marshal(map[string]any{"items": operations.StandupItems(s.Tasks()), "generated_at": time.Now().UTC()})
|
||||
e := domain.Event{ID: id(), Type: "StandupAdvisory", TaskID: "system", Version: 0, Payload: items}
|
||||
return e, s.Append(e)
|
||||
}
|
||||
mux.HandleFunc("/v1/standup", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
json.NewEncoder(w).Encode(operations.StandupItems(s.Tasks()))
|
||||
return
|
||||
}
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", 405)
|
||||
return
|
||||
}
|
||||
if err := authz.AuthorizeEvent(surface(r), "StandupAdvisory"); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
e, err := standup()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 400)
|
||||
return
|
||||
}
|
||||
json.NewEncoder(w).Encode(e)
|
||||
})
|
||||
mux.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
|
||||
tasks := s.Tasks()
|
||||
counts := map[domain.TaskState]int{}
|
||||
@@ -428,6 +453,22 @@ func main() {
|
||||
}
|
||||
}()
|
||||
}
|
||||
go func() {
|
||||
lastDay := ""
|
||||
t := time.NewTicker(time.Minute)
|
||||
defer t.Stop()
|
||||
for now := range t.C {
|
||||
utc := now.UTC()
|
||||
day := utc.Format("2006-01-02")
|
||||
if utc.Hour() == 3 && day != lastDay {
|
||||
if _, err := standup(); err != nil {
|
||||
log.Printf("standup advisory: %v", err)
|
||||
} else {
|
||||
lastDay = day
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
port := os.Getenv("ORCHESTRA_PORT")
|
||||
if port == "" {
|
||||
port = "9145"
|
||||
|
||||
Reference in New Issue
Block a user