Fill and expose oplog in cache-service
parent
b7822498b1
commit
9416613627
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue