mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
d8e42744b4
* fix: move eventstore pkgs * fix: move eventstore pkgs * fix: remove v2 view * fix: remove v2 view
41 lines
1015 B
Go
41 lines
1015 B
Go
package spooler
|
|
|
|
import (
|
|
"github.com/caos/zitadel/internal/eventstore/v1"
|
|
"math/rand"
|
|
"os"
|
|
|
|
"github.com/caos/logging"
|
|
"github.com/caos/zitadel/internal/eventstore/v1/query"
|
|
"github.com/caos/zitadel/internal/id"
|
|
)
|
|
|
|
type Config struct {
|
|
Eventstore v1.Eventstore
|
|
Locker Locker
|
|
ViewHandlers []query.Handler
|
|
ConcurrentWorkers int
|
|
}
|
|
|
|
func (c *Config) New() *Spooler {
|
|
lockID, err := os.Hostname()
|
|
if err != nil || lockID == "" {
|
|
lockID, err = id.SonyFlakeGenerator.Next()
|
|
logging.Log("SPOOL-bdO56").OnError(err).Panic("unable to generate lockID")
|
|
}
|
|
|
|
//shuffle the handlers for better balance when running multiple pods
|
|
rand.Shuffle(len(c.ViewHandlers), func(i, j int) {
|
|
c.ViewHandlers[i], c.ViewHandlers[j] = c.ViewHandlers[j], c.ViewHandlers[i]
|
|
})
|
|
|
|
return &Spooler{
|
|
handlers: c.ViewHandlers,
|
|
lockID: lockID,
|
|
eventstore: c.Eventstore,
|
|
locker: c.Locker,
|
|
queue: make(chan *spooledHandler, len(c.ViewHandlers)),
|
|
workers: c.ConcurrentWorkers,
|
|
}
|
|
}
|