chore: handle push of unchanged schema

This commit is contained in:
2022-10-14 22:41:56 +02:00
parent eb41e24002
commit b1124d6350
10 changed files with 866 additions and 61 deletions
+17 -10
View File
@@ -2,6 +2,7 @@ package cache
import (
"fmt"
"time"
"github.com/apex/log"
"github.com/sparetimecoders/goamqp"
@@ -12,17 +13,20 @@ import (
const subGraphKey = "%s<->%s"
type Cache struct {
services map[string]map[string]struct{}
subGraphs map[string]string
logger log.Interface
services map[string]map[string]struct{}
subGraphs map[string]string
lastUpdate map[string]string
logger log.Interface
}
func (c *Cache) Services(ref string) []string {
func (c *Cache) Services(ref, lastUpdate string) ([]string, string) {
var services []string
for k := range c.services[ref] {
services = append(services, k)
if lastUpdate == "" || c.lastUpdate[ref] > lastUpdate {
for k := range c.services[ref] {
services = append(services, k)
}
}
return services
return services, c.lastUpdate[ref]
}
func (c *Cache) SubGraphId(ref, service string) string {
@@ -37,12 +41,14 @@ func (c *Cache) Update(msg any, _ goamqp.Headers) (any, error) {
}
c.services[m.Ref][m.ID.String()] = struct{}{}
c.subGraphs[fmt.Sprintf(subGraphKey, m.Ref, m.Service)] = m.ID.String()
c.lastUpdate[m.Ref] = m.Time.Format(time.RFC3339Nano)
case *domain.SubGraph:
if _, exists := c.services[m.Ref]; !exists {
c.services[m.Ref] = make(map[string]struct{})
}
c.services[m.Ref][m.ID.String()] = struct{}{}
c.subGraphs[fmt.Sprintf(subGraphKey, m.Ref, m.Service)] = m.ID.String()
c.lastUpdate[m.Ref] = m.ChangedAt.Format(time.RFC3339Nano)
default:
c.logger.Warnf("unexpected message received: %+v", msg)
}
@@ -51,8 +57,9 @@ func (c *Cache) Update(msg any, _ goamqp.Headers) (any, error) {
func New(logger log.Interface) *Cache {
return &Cache{
subGraphs: make(map[string]string),
services: make(map[string]map[string]struct{}),
logger: logger,
subGraphs: make(map[string]string),
services: make(map[string]map[string]struct{}),
lastUpdate: make(map[string]string),
logger: logger,
}
}