Documentation ¶
Overview ¶
The watcher package provides an interface for observing changes to arbitrary MongoDB documents that are maintained via the mgo/txn transaction package.
Index ¶
- Variables
- func MustErr(w Errer) error
- func Stop(w Stopper, t *tomb.Tomb)
- type Change
- type Errer
- type Stopper
- type Watcher
- func (w *Watcher) Dead() <-chan struct{}
- func (w *Watcher) Err() error
- func (w *Watcher) StartSync()
- func (w *Watcher) Stop() error
- func (w *Watcher) Unwatch(collection string, id interface{}, ch chan<- Change)
- func (w *Watcher) UnwatchCollection(collection string, ch chan<- Change)
- func (w *Watcher) Watch(collection string, id interface{}, revno int64, ch chan<- Change)
- func (w *Watcher) WatchCollection(collection string, ch chan<- Change)
- func (w *Watcher) WatchCollectionWithFilter(collection string, ch chan<- Change, filter func(interface{}) bool)
Constants ¶
This section is empty.
Variables ¶
var Period time.Duration = 5 * time.Second
Period is the delay between each sync. It must not be changed when any watchers are active.
Functions ¶
Types ¶
type Change ¶
type Change struct { // C and Id hold the collection name and document _id field value. C string Id interface{} // Revno is the latest known value for the document's txn-revno // field, or -1 if the document was deleted. Revno int64 }
A Change holds information about a document change.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
A Watcher can watch any number of collections and documents for changes.
func New ¶
func New(changelog *mgo.Collection) *Watcher
New returns a new Watcher observing the changelog collection, which must be a capped collection maintained by mgo/txn.
func (*Watcher) Dead ¶
func (w *Watcher) Dead() <-chan struct{}
Dead returns a channel that is closed when the watcher has stopped.
func (*Watcher) Err ¶
Err returns the error with which the watcher stopped. It returns nil if the watcher stopped cleanly, tomb.ErrStillAlive if the watcher is still running properly, or the respective error if the watcher is terminating or has terminated with an error.
func (*Watcher) StartSync ¶
func (w *Watcher) StartSync()
StartSync forces the watcher to load new events from the database.
func (*Watcher) UnwatchCollection ¶
UnwatchCollection stops watching the given collection via ch.
func (*Watcher) Watch ¶
Watch starts watching the given collection and document id. An event will be sent onto ch whenever a matching document's txn-revno field is observed to change after a transaction is applied. The revno parameter holds the currently known revision number for the document. Non-existent documents are represented by a -1 revno.
func (*Watcher) WatchCollection ¶
WatchCollection starts watching the given collection. An event will be sent onto ch whenever the txn-revno field is observed to change after a transaction is applied for any document in the collection.
func (*Watcher) WatchCollectionWithFilter ¶
func (w *Watcher) WatchCollectionWithFilter(collection string, ch chan<- Change, filter func(interface{}) bool)
WatchCollectionWithFilter starts watching the given collection. An event will be sent onto ch whenever the txn-revno field is observed to change after a transaction is applied for any document in the collection, so long as the specified filter function returns true when called with the document id value.