Fill and expose oplog in cache-service

master
Bel LaPointe 2023-10-11 16:03:57 -06:00
parent b7822498b1
commit 9416613627
2 changed files with 18 additions and 2 deletions

View File

@ -16,8 +16,8 @@ type timestampedEvent struct {
}
// gotcha duration? bigger N? whatever
func NewOplog() Oplog {
return Oplog{
func NewOplog() *Oplog {
return &Oplog{
events: make([]timestampedEvent, 0, 1024),
}
}

View File

@ -5,16 +5,20 @@ import (
"log"
"net/http"
"render231011/internal/thestore"
"strconv"
"strings"
"time"
)
type Server struct {
store *thestore.Store
oplog *Oplog
}
func NewServer() Server {
return Server{
store: thestore.NewStore(),
oplog: NewOplog(),
}
}
@ -40,8 +44,20 @@ func (server Server) servePostEvent(w http.ResponseWriter, r *http.Request) {
// todo check if action==updated service-id already exists
server.store.Push(newEvent)
log.Printf("ingested event %+v", newEvent)
// todo store the op log
server.oplog.Push(newEvent)
}
func (server Server) serveGetEvents(w http.ResponseWriter, r *http.Request) {
// todo my circular queue magic
sinceString := r.URL.Query().Get("since")
sinceInt, err := strconv.ParseInt(sinceString, 10, 64)
if err != nil {
panic(err)
}
since := time.Unix(sinceInt, 0)
result := server.oplog.Since(since)
json.NewEncoder(w).Encode(result)
}