Fill and expose oplog in cache-service
parent
b7822498b1
commit
9416613627
|
|
@ -16,8 +16,8 @@ type timestampedEvent struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// gotcha duration? bigger N? whatever
|
// gotcha duration? bigger N? whatever
|
||||||
func NewOplog() Oplog {
|
func NewOplog() *Oplog {
|
||||||
return Oplog{
|
return &Oplog{
|
||||||
events: make([]timestampedEvent, 0, 1024),
|
events: make([]timestampedEvent, 0, 1024),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,20 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"render231011/internal/thestore"
|
"render231011/internal/thestore"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
store *thestore.Store
|
store *thestore.Store
|
||||||
|
oplog *Oplog
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer() Server {
|
func NewServer() Server {
|
||||||
return Server{
|
return Server{
|
||||||
store: thestore.NewStore(),
|
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
|
// todo check if action==updated service-id already exists
|
||||||
server.store.Push(newEvent)
|
server.store.Push(newEvent)
|
||||||
log.Printf("ingested event %+v", 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) {
|
func (server Server) serveGetEvents(w http.ResponseWriter, r *http.Request) {
|
||||||
// todo my circular queue magic
|
// 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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue