allow multiple event consumers per search instance

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg committed 2022-10-18 13:30:50 +02:00
1 parent 235b1b9ef9
commit 45a47eafb5
2 files changed
+42 -35

No files matched your search

+1
View File
@@ -5,6 +5,7 @@ type Events struct {
Endpoint string `yaml:"endpoint" env:"SEARCH_EVENTS_ENDPOINT" desc:"The address of the event system. The event system is the message queuing service. It is used as message broker for the microservice architecture."`
Cluster string `yaml:"cluster" env:"SEARCH_EVENTS_CLUSTER" desc:"The clusterID of the event system. The event system is the message queuing service. It is used as message broker for the microservice architecture. Mandatory when using NATS as event system."`
AsyncUploads bool `yaml:"async_uploads" env:"STORAGE_USERS_OCIS_ASYNC_UPLOADS;SEARCH_EVENTS_ASYNC_UPLOADS" desc:"Enable asynchronous file uploads."`
NumConsumers int `yaml:"num_consumers" env:"SEARCH_EVENTS_NUM_CONSUMERS" desc:"number of event consumers per service instance"`
TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_INSECURE;SEARCH_EVENTS_TLS_INSECURE" desc:"Whether to verify the server TLS certificates."`
TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"SEARCH_EVENTS_TLS_ROOT_CA_CERTIFICATE" desc:"The root CA certificate used to validate the server's TLS certificate. If provided SEARCH_EVENTS_TLS_INSECURE will be seen as false."`
+41 -35
View File
@@ -48,43 +48,49 @@ func HandleEvents(eng engine.Engine, extractor content.Extractor, gw gateway.Gat
return err
}
go func(eh *eventHandler, ch <-chan interface{}) {
for e := range ch {
eh.logger.Debug().Interface("event", e).Msg("updating index")
if cfg.Events.NumConsumers == 0 {
cfg.Events.NumConsumers = 1
}
switch ev := e.(type) {
case events.ItemTrashed:
eh.trashItem(ev.ID)
case events.ItemMoved:
eh.moveItem(ev.Ref, ev.Executant)
case events.ItemRestored:
eh.restoreItem(ev.Ref, ev.Executant)
case events.ContainerCreated:
eh.upsertItem(ev.Ref, ev.Executant)
case events.FileTouched:
eh.upsertItem(ev.Ref, ev.Executant)
case events.FileVersionRestored:
eh.upsertItem(ev.Ref, ev.Executant)
case events.FileUploaded:
eh.upsertItem(ev.Ref, ev.Executant)
case events.UploadReady:
eh.upsertItem(ev.FileRef, ev.ExecutingUser.Id)
case events.TagsAdded:
eh.upsertItem(ev.Ref, ev.Executant)
case events.TagsRemoved:
eh.upsertItem(ev.Ref, ev.Executant)
for i := 0; i < cfg.Events.NumConsumers; i++ {
go func(eh *eventHandler, ch <-chan interface{}) {
for e := range ch {
eh.logger.Debug().Interface("event", e).Msg("updating index")
switch ev := e.(type) {
case events.ItemTrashed:
eh.trashItem(ev.ID)
case events.ItemMoved:
eh.moveItem(ev.Ref, ev.Executant)
case events.ItemRestored:
eh.restoreItem(ev.Ref, ev.Executant)
case events.ContainerCreated:
eh.upsertItem(ev.Ref, ev.Executant)
case events.FileTouched:
eh.upsertItem(ev.Ref, ev.Executant)
case events.FileVersionRestored:
eh.upsertItem(ev.Ref, ev.Executant)
case events.FileUploaded:
eh.upsertItem(ev.Ref, ev.Executant)
case events.UploadReady:
eh.upsertItem(ev.FileRef, ev.ExecutingUser.Id)
case events.TagsAdded:
eh.upsertItem(ev.Ref, ev.Executant)
case events.TagsRemoved:
eh.upsertItem(ev.Ref, ev.Executant)
}
}
}
}(
&eventHandler{
logger: logger,
engine: eng,
secret: cfg.MachineAuthAPIKey,
gateway: gw,
extractor: extractor,
},
ch,
)
}(
&eventHandler{
logger: logger,
engine: eng,
secret: cfg.MachineAuthAPIKey,
gateway: gw,
extractor: extractor,
},
ch,
)
}
return nil
}