mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
584bcda108
* fix(searchlimit): increase to 1000 * rafactor: remove unused return * fix(user): marshalling of language tag * fix(spooler): shuffle handlers on start * fix(sql): reduce max open conns from 200 to 25 per pod * chore(deps): google.golang.org/grpc and github.com/lib/pq * chore(deps): update github.com/cockroachdb/cockroach-go/v2
41 lines
1017 B
Go
41 lines
1017 B
Go
package spooler
|
|
|
|
import (
|
|
"math/rand"
|
|
"os"
|
|
|
|
"github.com/caos/logging"
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
"github.com/caos/zitadel/internal/eventstore/query"
|
|
"github.com/caos/zitadel/internal/id"
|
|
)
|
|
|
|
type Config struct {
|
|
Eventstore eventstore.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,
|
|
}
|
|
}
|