mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
aed7010508
* fix: improve scheduling * build pre-release * fix: locker * fix: user handler and print stack in case of panic in reducer * chore: remove sentry * fix: improve handler projection and implement tests * more tests * fix: race condition in tests * Update internal/eventstore/repository/sql/query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix: implemented suggested changes * fix: lock statement Co-authored-by: Silvan <silvan.reusser@gmail.com>
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package spooler
|
|
|
|
import (
|
|
"math/rand"
|
|
|
|
"github.com/zitadel/logging"
|
|
|
|
v1 "github.com/zitadel/zitadel/internal/eventstore/v1"
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/query"
|
|
"github.com/zitadel/zitadel/internal/id"
|
|
)
|
|
|
|
type Config struct {
|
|
Eventstore v1.Eventstore
|
|
Locker Locker
|
|
ViewHandlers []query.Handler
|
|
ConcurrentWorkers int
|
|
ConcurrentInstances int
|
|
}
|
|
|
|
func (c *Config) New() *Spooler {
|
|
lockID, err := id.SonyFlakeGenerator().Next()
|
|
logging.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,
|
|
concurrentInstances: c.ConcurrentInstances,
|
|
}
|
|
}
|