2020-04-29 10:11:13 +00:00
|
|
|
package spooler
|
|
|
|
|
|
|
|
import (
|
2020-07-28 07:42:21 +00:00
|
|
|
"os"
|
|
|
|
|
2020-04-29 10:11:13 +00:00
|
|
|
"github.com/caos/logging"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
2020-07-28 07:42:21 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/query"
|
2020-05-28 11:28:36 +00:00
|
|
|
"github.com/caos/zitadel/internal/id"
|
2020-04-29 10:11:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2020-07-28 07:42:21 +00:00
|
|
|
Eventstore eventstore.Eventstore
|
|
|
|
Locker Locker
|
|
|
|
ViewHandlers []query.Handler
|
|
|
|
ConcurrentWorkers int
|
2020-04-29 10:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) New() *Spooler {
|
2020-07-28 07:42:21 +00:00
|
|
|
lockID, err := os.Hostname()
|
|
|
|
if err != nil || lockID == "" {
|
|
|
|
lockID, err = id.SonyFlakeGenerator.Next()
|
|
|
|
logging.Log("SPOOL-bdO56").OnError(err).Panic("unable to generate lockID")
|
|
|
|
}
|
2020-04-29 10:11:13 +00:00
|
|
|
|
|
|
|
return &Spooler{
|
2020-07-28 07:42:21 +00:00
|
|
|
handlers: c.ViewHandlers,
|
|
|
|
lockID: lockID,
|
|
|
|
eventstore: c.Eventstore,
|
|
|
|
locker: c.Locker,
|
|
|
|
queue: make(chan *spooledHandler),
|
|
|
|
workers: c.ConcurrentWorkers,
|
2020-04-29 10:11:13 +00:00
|
|
|
}
|
|
|
|
}
|