mirror of
https://github.com/zitadel/zitadel.git
synced 2025-10-26 09:09:14 +00:00
fix(event handling): use internal pubsub for view update (#1118)
* start sub * start implement subsciptions * start subscription * implementation for member done * admin done * fix: tests * extend handlers * prepary notification * no errors in adminapi * changed current sequence in all packages * ignore mocks * works * subscriptions as singleton * tests * refactor: rename function scope var
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
notificationTable = "notification.notifications"
|
||||
)
|
||||
|
||||
func (v *View) GetLatestNotificationSequence() (*repository.CurrentSequence, error) {
|
||||
return v.latestSequence(notificationTable)
|
||||
func (v *View) GetLatestNotificationSequence(aggregateType string) (*repository.CurrentSequence, error) {
|
||||
return v.latestSequence(notificationTable, aggregateType)
|
||||
}
|
||||
|
||||
func (v *View) ProcessedNotificationSequence(eventSequence uint64, eventTimestamp time.Time) error {
|
||||
return v.saveCurrentSequence(notificationTable, eventSequence, eventTimestamp)
|
||||
func (v *View) ProcessedNotificationSequence(event *models.Event) error {
|
||||
return v.saveCurrentSequence(notificationTable, event)
|
||||
}
|
||||
|
||||
func (v *View) UpdateNotificationSpoolerRunTimestamp() error {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/user/repository/view"
|
||||
"github.com/caos/zitadel/internal/user/repository/view/model"
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -15,13 +15,13 @@ func (v *View) NotifyUserByID(userID string) (*model.NotifyUser, error) {
|
||||
return view.NotifyUserByID(v.Db, notifyUserTable, userID)
|
||||
}
|
||||
|
||||
func (v *View) PutNotifyUser(user *model.NotifyUser, sequence uint64, eventTimestamp time.Time) error {
|
||||
func (v *View) PutNotifyUser(user *model.NotifyUser, event *models.Event) error {
|
||||
err := view.PutNotifyUser(v.Db, notifyUserTable, user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if sequence != 0 {
|
||||
return v.ProcessedNotifyUserSequence(sequence, eventTimestamp)
|
||||
if event.Sequence != 0 {
|
||||
return v.ProcessedNotifyUserSequence(event)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -30,20 +30,20 @@ func (v *View) NotifyUsersByOrgID(orgID string) ([]*model.NotifyUser, error) {
|
||||
return view.NotifyUsersByOrgID(v.Db, notifyUserTable, orgID)
|
||||
}
|
||||
|
||||
func (v *View) DeleteNotifyUser(userID string, eventSequence uint64, eventTimestamp time.Time) error {
|
||||
func (v *View) DeleteNotifyUser(userID string, event *models.Event) error {
|
||||
err := view.DeleteNotifyUser(v.Db, notifyUserTable, userID)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return v.ProcessedNotifyUserSequence(eventSequence, eventTimestamp)
|
||||
return v.ProcessedNotifyUserSequence(event)
|
||||
}
|
||||
|
||||
func (v *View) GetLatestNotifyUserSequence() (*repository.CurrentSequence, error) {
|
||||
return v.latestSequence(notifyUserTable)
|
||||
func (v *View) GetLatestNotifyUserSequence(aggregateType string) (*repository.CurrentSequence, error) {
|
||||
return v.latestSequence(notifyUserTable, aggregateType)
|
||||
}
|
||||
|
||||
func (v *View) ProcessedNotifyUserSequence(eventSequence uint64, eventTimestamp time.Time) error {
|
||||
return v.saveCurrentSequence(notifyUserTable, eventSequence, eventTimestamp)
|
||||
func (v *View) ProcessedNotifyUserSequence(event *models.Event) error {
|
||||
return v.saveCurrentSequence(notifyUserTable, event)
|
||||
}
|
||||
|
||||
func (v *View) UpdateNotifyUserSpoolerRunTimestamp() error {
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
"time"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/view/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
sequencesTable = "notification.current_sequences"
|
||||
)
|
||||
|
||||
func (v *View) saveCurrentSequence(viewName string, sequence uint64, eventTimestamp time.Time) error {
|
||||
return repository.SaveCurrentSequence(v.Db, sequencesTable, viewName, sequence, eventTimestamp)
|
||||
func (v *View) saveCurrentSequence(viewName string, event *models.Event) error {
|
||||
return repository.SaveCurrentSequence(v.Db, sequencesTable, viewName, string(event.AggregateType), event.Sequence, event.CreationDate)
|
||||
}
|
||||
|
||||
func (v *View) latestSequence(viewName string) (*repository.CurrentSequence, error) {
|
||||
return repository.LatestSequence(v.Db, sequencesTable, viewName)
|
||||
func (v *View) latestSequence(viewName, aggregateType string) (*repository.CurrentSequence, error) {
|
||||
return repository.LatestSequence(v.Db, sequencesTable, viewName, aggregateType)
|
||||
}
|
||||
|
||||
func (v *View) updateSpoolerRunSequence(viewName string) error {
|
||||
currentSequence, err := repository.LatestSequence(v.Db, sequencesTable, viewName)
|
||||
currentSequence, err := repository.LatestSequence(v.Db, sequencesTable, viewName, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -26,5 +28,8 @@ func (v *View) updateSpoolerRunSequence(viewName string) error {
|
||||
currentSequence.ViewName = viewName
|
||||
}
|
||||
currentSequence.LastSuccessfulSpoolerRun = time.Now()
|
||||
//update all aggregate types
|
||||
//TODO: not sure if all scenarios work as expected
|
||||
currentSequence.AggregateType = ""
|
||||
return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user