garm/database/common/watcher.go
Gabriel Adrian Samfira 8d57fc8fa2 Add rudimentary database watcher
Adds a simple database watcher. At this point it's just one process, but
the plan is to allow different implementations that inform the local running
workers of changes that have occured on entities of interest in the database.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2024-06-14 19:47:12 +00:00

50 lines
1.3 KiB
Go

package common
type (
DatabaseEntityType string
OperationType string
PayloadFilterFunc func(ChangePayload) bool
)
const (
RepositoryEntityType DatabaseEntityType = "repository"
OrganizationEntityType DatabaseEntityType = "organization"
EnterpriseEntityType DatabaseEntityType = "enterprise"
PoolEntityType DatabaseEntityType = "pool"
UserEntityType DatabaseEntityType = "user"
InstanceEntityType DatabaseEntityType = "instance"
JobEntityType DatabaseEntityType = "job"
ControllerEntityType DatabaseEntityType = "controller"
GithubCredentialsEntityType DatabaseEntityType = "github_credentials"
GithubEndpointEntityType DatabaseEntityType = "github_endpoint"
)
const (
CreateOperation OperationType = "create"
UpdateOperation OperationType = "update"
DeleteOperation OperationType = "delete"
)
type ChangePayload struct {
EntityType DatabaseEntityType
Operation OperationType
Payload interface{}
}
type Consumer interface {
Watch() <-chan ChangePayload
IsClosed() bool
Close()
SetFilters(filters ...PayloadFilterFunc)
}
type Producer interface {
Notify(ChangePayload) error
IsClosed() bool
Close()
}
type Watcher interface {
RegisterProducer(ID string) (Producer, error)
RegisterConsumer(ID string, filters ...PayloadFilterFunc) (Consumer, error)
}