-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from gabriel-samfira/add-database-watcher
Add database watcher
- Loading branch information
Showing
27 changed files
with
1,900 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package common | ||
|
||
import "fmt" | ||
|
||
var ( | ||
ErrProducerClosed = fmt.Errorf("producer is closed") | ||
ErrProducerTimeoutErr = fmt.Errorf("producer timeout error") | ||
ErrProducerAlreadyRegistered = fmt.Errorf("producer already registered") | ||
ErrConsumerAlreadyRegistered = fmt.Errorf("consumer already registered") | ||
ErrWatcherAlreadyStarted = fmt.Errorf("watcher already started") | ||
ErrWatcherNotInitialized = fmt.Errorf("watcher not initialized") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package common | ||
|
||
import "context" | ||
|
||
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" // #nosec G101 | ||
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(ctx context.Context, ID string) (Producer, error) | ||
RegisterConsumer(ctx context.Context, ID string, filters ...PayloadFilterFunc) (Consumer, error) | ||
Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.